Newbie problem with codecs
Alex Martelli
aleax at aleax.it
Thu Aug 21 02:34:06 EDT 2003
Andrew Dalke wrote:
...
> 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 "."?
A dot, not a comma -- sorry, the font I use makes them hard
to tell apart (at least w/my failing eyesight) and they're right
next to each other on the keyboard... which I guess is why I
think you have dots on both sides of "instead" in your phrase?-).
> 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.
Perfectly right -- codecs.BOM_UTF16_LE is just a 2-character
string which doesn't name a codec (but rather gives the BOM
for one). I saw that obvious-cause NameError and didn't look
any deeper -- thanks for doing so.
> 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>)
>>>>
I won't dare guess, but it's certainly one possibility.
Alex
More information about the Python-list
mailing list