471,325 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Lookup encoding aliases in Python 2.4

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


Batteries not included; you put it together.
Jul 17 '07 #1
0 987

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.