> Having just followed this thread tangentially, I do have to say it > seems quite cool to be able to do something like the following in > Python 2.2: > > >>> s = msg['from'] > >>> parts = s.split('?') > >>> if parts[2].lower() == 'q': > ... name = parts[3].decode('quopri') > ... elif parts[2].lower() == 'b': > ... name = parts[3].decode('base64') > ... What is the type of parts[3] here? If it is a plain string, it is already possible: >>> 'SGVsbG8=\n'.decode("base64") 'Hello' I doubt you'd ever have a Unicode string that represents a base64-encoded byte string, and if you had, .decode would probably do the wrong thing: >>> import codecs >>> enc,dec,_,_ = codecs.lookup("base64") >>> dec(u'SGVsbG8=\n') ('Hello', 9) Note that this returns a byte string, not a Unicode string. Regards, Martin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4