Your web host failed to compile Python correctly; talk with them.
>This seemed insane to me, so I tried Python from the command line.
>Same thing, but when I import it *again* it works:
No, it didn't. Python caches import names even when the import fails
(protects against circular references); try using the cgi module for
anything that requires a socket and it'll die. It might work for the
other functions in the cgi module, depending on when cgi tried to import
the socket code.
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/
"I had lots of reasonable theories about children myself, until I
had some." --Michael Rios
I thought about this for a while and suppose I can see how it
protects against circular reference problems (I'm guessing it
creates a new module object and stores it in sys.modules
immediately upon encountering the import statement, and only
subsequently does it try to import and execute the contents),
but what I don't understand is why it doesn't clean up after
itself in the case of a failed import.
Should it not be considered a bug that a failed import leaves
a broken module around?
Is it possible to redefine this so that it cleanly removes the
newly created reference if an import fails?
Or would it then be a problem that circularly imported modules
might now have references back to a module which appears never
to have been imported (because it failed, and was deleted)?
And have I now answered all my questions? :-)
-Peter
Lots of people think so, but every time this comes up on python-dev,
someone fumbles around and eventually remembers exactly why it has to
work this way -- but I'm never the someone.
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/
Project Vote Smart: http://www.vote-smart.org/