Why the inconsistent of those two base64 methods?
Maarten
maarten.sneep at knmi.nl
Wed May 12 05:20:11 EDT 2010
On May 12, 6:04 am, Leo Jay <python.leo... at gmail.com> wrote:
> I'd like to encode a string in base64, but I found a inconsistent of
> two methods:
>
> >>> 'aaa'.encode('base64')
> 'YWFh\n'
> >>> import base64
> >>> base64.b64encode('aaa')
> 'YWFh'
>
> as you can see, the result of
> 'aaa'.encode('base64')
> has a '\n' at the end, but the other method doesn't.
>
> Why the inconsistent?
Don't know. Does it matter?
>>> import base64
>>> base64.decodestring(base64.b64encode('aaa'))
'aaa'
>>> 'aaa'.encode('base64').decode('base64')
'aaa'
(so far so good, and as expected)
>>> base64.decodestring('aaa'.encode('base64'))
'aaa'
>>> base64.b64encode('aaa').decode('base64')
'aaa'
(As far as I can see, both methods are completely consistent)
Maarten
More information about the Python-list
mailing list