I'm starting in Python
and I'm coming from PHP
.
To convert a string to base 64 in PHP, I do it as follows:
base64_encode('stack overflow'); //c3RhY2sgb3ZlcmZsb3c=
And in Python
, how do I do this?
I'm starting in Python
and I'm coming from PHP
.
To convert a string to base 64 in PHP, I do it as follows:
base64_encode('stack overflow'); //c3RhY2sgb3ZlcmZsb3c=
And in Python
, how do I do this?
It's similar. You only have to import
:
>>> import base64
>>> encoded = base64.b64encode(b'stack overflow')
b'c3RhY2sgb3ZlcmZsb3c='
b64encode
requests an array of bytes, not a string . b
up front does this conversion.