Newbie problem with codecs

Andrew Dalke adalke at
Thu Aug 21 07:50:23 CEST 2003

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

> 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\", 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.  ;)

                    dalke at

More information about the Python-list mailing list