Using base64 to encode/decode data
ascii character to store it more safely.
base64 module is an efficient choice to do so.
It uses characters from this set
('=' is used for padding at the end.)
ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 0123456789+/
Here's how to use it.
>>> import base64 >>> base64.encodestring('hello world') 'aGVsbG8gd29ybGQ=\n' >>> base64.decodestring(_) 'hello world' >>>
If the text is long, the base64 module will split
the encoded data into multiple lines.
If you don't wan't it to be split. You can use
binascii.b2a_base64 instead of base64.encodestring and
binascii.a2b_base64 instead of base64.decodestring