2.1 strangness

Andreas Jung andreas at andreas-jung.com
Thu May 31 12:38:45 EDT 2001


"Robin Becker" <robin at jessikat.fsnet.co.uk> schrieb im Newsbeitrag
news:lCoIXKAB3mF7Ew5A at jessikat.demon.co.uk...
> This is a condensation of some weirds I'm seeing with M2Crypto which I
> downloaded today; I'm running SF 2.1 for win32
>
> ##################################
> #file ttt.py
> from httplib import *
>
> class Bongo(HTTPConnection):
>         pass
> ##################################
>
> when I attempt to run this
>
> C:\Python\devel\m2crypto-0.06-snap5-win32\demo\ssl>python \tmp\ttt.py
> Traceback (most recent call last):
>   File "\tmp\ttt.py", line 3, in ?
>     class Bongo(HTTPConnection):
> NameError: name 'HTTPConnection' is not defined
>
> but certainly httplib has a class HTTPConnection
>
> is this the famous blow up in your face from the future concerning
> shadowed globals? It seems rather nasty to me, but then I objected to
> the original static scoping stuff. This seems entirely module level so
> what gives?

Your "from httplib import *" is the problem. Since Python 2.1 (?) only
elements definied in module.__all__ will be imported by 'import *'.
httplib.__all__ is ['HTTP']. Better you 'import httplib'
and use 'httplib.HTTPConnection' - much cleaner ...and it works.

Andreas












More information about the Python-list mailing list