[Python-Dev] Adding .decode() method to Unicode

Fredrik Lundh fredrik@pythonware.com
Tue, 12 Jun 2001 16:45:16 +0200


barry wrote:

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

uhuh?  and how exactly is this cooler than being able to do
something like the following:

    import quopri, base64
    s = msg['from']
    parts = s.split('?')
    if parts[2].lower() == 'q':
        name = quopri.decodestring(parts[3])
    elif parts[2].lower() == 'b':
        name = base64.decodestring(parts[3])

(going through the codec registry is slower, and imports more
modules, but what's so cool with that?)

</F>