Lookup encoding aliases in Python 2.4

O

Omari Norman

My program creates new XML files (not through the DOM, but just by
simple file.write calls.) It would be nice if said files would
be in the default system encoding. So in Python 2.5 I use

ENCODING = codecs.lookup(locale.getdefaultlocale()[1]).name

locale.getdefaultlocale()[1] sometimes returns a non-canonical encoding
name, such as 'UTF8'. This gives the xml.sax parser a fit, so I use
codecs.lookup to convert the alias to the canonical encoding name. I
then write this encoding in the top line of the XML file.

Python 2.4's codecs.lookup works differently--it does not return names.
Is there any way to accomplish this in Python 2.4? I went looking
through the codecs module in 2.5 to see if I could find a dict with the
aliases, to no avail. I suppose the worst-case scenario is that I make a
dict myself with common encodings in it (or, just tell people to use
Python 2.5.)

Thanks,
Omari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top