Gustavo Picon is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

tabo / numconv

Python library to convert strings to numbers and numbers to strings. Docs: http://docs.tabo.pe/numconv/tip/

Clone this repository (size: 168.1 KB): HTTPS / SSH
hg clone https://bitbucket.org/tabo/numconv
hg clone ssh://hg@bitbucket.org/tabo/numconv

numconv / docs / index.rst

commit
3e4be71ff667
parent
187f7fe4e68c
branch
default

Python version info.

1
a507bcdecc11
numconv
2
a507bcdecc11
=======
3
0928d42622f4
4
187f7fe4e68c
`numconv <https://tabo.pe/projects/numconv/>`_ is a library that converts
5
187f7fe4e68c
strings to numbers and numbers to strings using default or user supplied
6
187f7fe4e68c
encoding alphabets, written by `Gustavo Picón <https://tabo.pe>`_ and
7
187f7fe4e68c
licensed under the Apache License 2.0.
8
0928d42622f4
9
187f7fe4e68c
Installation
10
187f7fe4e68c
------------
11
7c4b7067b2fc
12
3e4be71ff667
``numconv`` has been tested in Python 2.4, 2.5, 2.6, 2.7, 3.0 and 3.1. Other
13
3e4be71ff667
versions may work but are not supported.
14
3e4be71ff667
15
187f7fe4e68c
You have several ways to install ``numconv``. If you're not sure,
16
187f7fe4e68c
`just use pip <http://guide.python-distribute.org/pip.html>`_
17
187f7fe4e68c
18
187f7fe4e68c
pip (or easy_install)
19
187f7fe4e68c
~~~~~~~~~~~~~~~~~~~~~
20
187f7fe4e68c
21
187f7fe4e68c
You can install the release versions from
22
187f7fe4e68c
`numconv's PyPI page`_ using ``pip``::
23
187f7fe4e68c
24
187f7fe4e68c
  pip install numconv
25
187f7fe4e68c
26
187f7fe4e68c
or if for some reason you can't use ``pip``, you can try ``easy_install``::
27
187f7fe4e68c
28
187f7fe4e68c
  easy_install --always-unzip numconv
29
187f7fe4e68c
30
187f7fe4e68c
31
187f7fe4e68c
setup.py
32
187f7fe4e68c
~~~~~~~~
33
187f7fe4e68c
34
187f7fe4e68c
Download a release from the `numconv download page`_ and unpack it, then
35
187f7fe4e68c
run::
36
187f7fe4e68c
37
187f7fe4e68c
   python setup.py install
38
187f7fe4e68c
39
187f7fe4e68c
40
187f7fe4e68c
API
41
187f7fe4e68c
---
42
7c4b7067b2fc
43
a507bcdecc11
.. module:: numconv
44
7c4b7067b2fc
45
a507bcdecc11
.. autoclass:: NumConv
46
0928d42622f4
47
a507bcdecc11
   .. automethod:: int2str
48
a507bcdecc11
49
a507bcdecc11
      **Examples** (taken from :file:`tests.py`):
50
a507bcdecc11
51
a507bcdecc11
        3735928559 to hexadecimal::
52
a507bcdecc11
53
a507bcdecc11
            >> NumConv(16).int2str(3735928559)
54
a507bcdecc11
            'DEADBEEF'
55
a507bcdecc11
56
a507bcdecc11
        19284 to binary::
57
a507bcdecc11
58
a507bcdecc11
            >> NumConv(2).int2str(19284)
59
a507bcdecc11
            '100101101010100'
60
a507bcdecc11
61
a507bcdecc11
        37 to base 4 using a custom dictionary::
62
a507bcdecc11
63
a507bcdecc11
            >> NumConv(4, 'rofl').int2str(37)
64
a507bcdecc11
            'foo'
65
a507bcdecc11
66
a507bcdecc11
        Very large number to :data:`~numconv.BASE85`::
67
a507bcdecc11
68
a507bcdecc11
            >> NumConv(85).int2str(2693233728041137)
69
a507bcdecc11
            '~123AFz@'
70
a507bcdecc11
71
a507bcdecc11
   .. automethod:: str2int
72
a507bcdecc11
73
a507bcdecc11
      **Examples** (taken from :file:`tests.py`):
74
a507bcdecc11
75
a507bcdecc11
        Hexadecimal 'DEADBEEF' to integer::
76
a507bcdecc11
77
a507bcdecc11
           >> NumConv(16).str2int('DEADBEEF')
78
a507bcdecc11
           3735928559
79
a507bcdecc11
80
a507bcdecc11
        Binary '100101101010100' to integer::
81
a507bcdecc11
82
a507bcdecc11
            >> NumConv(2).str2int('100101101010100')
83
a507bcdecc11
            19284
84
a507bcdecc11
85
a507bcdecc11
        Base 4 with custom encoding 'foo' to integer::
86
a507bcdecc11
87
a507bcdecc11
            >> NumConv(4, 'rofl').str2int('foo')
88
a507bcdecc11
            37
89
a507bcdecc11
90
a507bcdecc11
        :data:`~numconv.BASE85` '~123AFz@' to integer::
91
a507bcdecc11
92
a507bcdecc11
            >> NumConv(85).str2int('~123AFz@')
93
a507bcdecc11
            2693233728041137
94
a507bcdecc11
95
a507bcdecc11
96
a507bcdecc11
.. data:: BASE85
97
a507bcdecc11
98
a507bcdecc11
   Alphabet defined in section 4 of :rfc:`1924`. Supposed to be a joke
99
a507bcdecc11
   (it is an April's fools RFC after all), but is quite useful because
100
a507bcdecc11
   it can be used as a base for the most common numeric conversions.
101
a507bcdecc11
102
a507bcdecc11
.. data:: BASE16
103
a507bcdecc11
          BASE32
104
a507bcdecc11
          BASE32HEX
105
a507bcdecc11
          BASE64
106
a507bcdecc11
          BASE64URL
107
a507bcdecc11
108
a507bcdecc11
   Alphabets defined in :rfc:`4648`. Not really for common numeric
109
a507bcdecc11
   conversion use.
110
a507bcdecc11
111
a507bcdecc11
.. data:: BASE62
112
a507bcdecc11
113
a507bcdecc11
   Useful for URL shorteners.
114
a507bcdecc11
115
a507bcdecc11
116
a507bcdecc11
.. autofunction:: int2str
117
a507bcdecc11
118
a507bcdecc11
.. autofunction:: str2int
119
0928d42622f4
120
0928d42622f4
121
0928d42622f4
122
0928d42622f4
Indices and tables
123
0928d42622f4
==================
124
0928d42622f4
125
0928d42622f4
* :ref:`genindex`
126
0928d42622f4
* :ref:`modindex`
127
0928d42622f4
* :ref:`search`
128
0928d42622f4
129
187f7fe4e68c
130
187f7fe4e68c
131
187f7fe4e68c
.. _`numconv's PyPI page`:
132
187f7fe4e68c
   http://pypi.python.org/pypi/numconv
133
187f7fe4e68c
.. _`numconv download page`:
134
187f7fe4e68c
   http://code.tabo.pe/numconv/downloads/
135
187f7fe4e68c