In Python 2, I used to could do this:
>>> var='this is a simple string'
>>> var.encode('base64')
'dGhpcyBpcyBhIHNpbXBsZSBzdHJpbmc=\n'
Easy! Unfortunately, this don't work in Python 3. Luckily, I was able to find an alternative way of accomplishing the same thing in Python 3:
>>> var='this is a simple string'
>>> import base64
>>> base64.b64encode(var.encode()).decode()
'dGhpcyBpcyBhIHNpbXBsZSBzdHJpbmc='
But that's terrible! There has to be a better way! So, I did some digging and found a second, alternative method of accomplishing what used to be a super simple task:
>>> var='this is a simple string'
>>> import codecs
>>> codecs.encode(var.encode(),"base64_codec").decode()
'dGhpcyBpcyBhIHNpbXBsZSBzdHJpbmc=\n'
That's even worse! I don't care about the trailing newline! What I care about is, jeez, there's gotta to be a better way to do this in Python 3, right?
I'm not asking "why". I'm asking if there is a better way to handle this simple case.