On May 12, 6:04 am, Leo Jay <python.leo...@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 -- http://mail.python.org/mailman/listinfo/python-list