Newbie problem with codecs

Andrew Dalke adalke at mindspring.com
Thu Aug 21 01:50:23 EDT 2003


derek / nul wrote:
> >   File "apply_physics.py", line 12, in ?
> >     codecs.lookup(BOM_UTF16_LE)
> > NameError: name 'BOM_UTF16_LE' is not defined

Alex
> Change the statement to:
> codecs.lookup(codecs,BOM_UTF16_LE)

Typo?  Shouldn't that be a "." instead of a "."?

In any case

>>> codecs.lookup(codecs.BOM_UTF16_LE)
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "C:\PYTHON23\Lib\encodings\__init__.py", line 84, in search_function
    globals(), locals(), _import_tail)
ValueError: Empty module name
>>>

In any case, the "BOM" means "byte order marker" and
the constant is the string prefix used to indicate which
UTF16 encoding is used.  It isn't the encoding name.

Perhaps the following is what the OP wanted?

>>> codecs.lookup("utf-16-le")
(<built-in function utf_16_le_encode>, <built-in function utf_16_le_decode>,
<class encodings.utf_16_le.StreamReader at 0x01396840>, <class
encodings.utf_16_le.StreamWriter at 0x01396810>)
>>>

But I am not Martin.  ;)

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list