[Python-Dev] Embedded python on Win2K, import failures

M.-A. Lemburg mal@lemburg.com
Sat, 12 Apr 2003 13:49:11 +0200

Martin v. L=F6wis wrote:
> "M.-A. Lemburg" <mal@lemburg.com> writes:
>>This looks like a modified site.py. Where did you get this from ?
> Perhaps from the Python CVS?

Hmm, I don't have that in my CVS checkout... I guess a cleanup
is due.

> if sys.platform =3D=3D 'win32':
>     import locale, codecs
>     enc =3D locale.getdefaultlocale()[1]
>     if enc.startswith('cp'):            # "cp***" ?
>         try:
>             codecs.lookup(enc)
>         except LookupError:
>             import encodings
>             encodings._cache[enc] =3D encodings._unknown
>             encodings.aliases.aliases[enc] =3D 'mbcs'

That's the wrong way to do it.

This code should live in encodings/__init__.py, not site.py,
and it should be done lazy, ie. Python startup time should not
suffer from this in general, only when Unicode and cpXXX
encodings are being requested and not found.

The codec machinery was carefully designed not to introduce
extra overhead when not using Unicode in programs. The above
approach pretty much kills this effort :-)

Marc-Andre Lemburg

Professional Python Software directly from the Source  (#1, Apr 12 2003)
 >>> Python/Zope Products & Consulting ...         http://www.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
EuroPython 2003, Charleroi, Belgium:                        73 days left