[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Programmatically discovering encoding types supported by codecs module

python

3/24/2010 5:56:00 PM

Benjamin,

> According to my brief messing around with the REPL, encodings.aliases.aliases is a good place to start. I don't know of any way to get the Language column, but at the very least that will give you most of the supported encodings and any aliases they have.

Thank you - that's exactly the type of information I was looking for.

I'm including the following for anyone browsing the mailing list
archives in the future.

Here's the snippet we're using to dynamically generate the codec
documentation posted on the docs.python website.

import encodings
encodingDict = encodings.aliases.aliases
encodingType = dict()
for key, value in encodingDict.items():
if value not in encodingType:
encodingType[ value ] = list()
encodingType[ value ].append( key )

for key in sorted( encodingType.keys() ):
aliases = sorted( encodingType[ key ] )
aliases = ', '.join( aliases )
print '%-20s%s' % ( key, aliases )

Regards,
Malcolm