From: Leo Jay on
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?
Thanks.

--
Best Regards,
Leo Jay
From: Maarten on
On May 12, 6:04 am, Leo Jay <python.leo...(a)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
From: Mensanator on
On May 12, 4:20 am, Maarten <maarten.sn...(a)knmi.nl> wrote:
> On May 12, 6:04 am, Leo Jay <python.leo...(a)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?

Yeah...

>>> import base64
>>> a = 'aaa'.encode('base64')
>>> aa = base64.b64encode('aaa')
>>> a == aa
False


>
> >>> 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)

Your notion of 'consistency' is wanting.

>
> Maarten