Newbie: A very basic problem related to

Peter Hansen peter at
Mon Dec 20 16:00:27 CET 2004

Ali wrote:
> Okay, i don't know what the problem is...
> I ran python in interactive mode and tried "import" and i got
> the same error... 
> Any ideas?

Probably nothing really helpful, I'm afraid.  Still, try
these ones out:

1. When you tried "import" from the interactive prompt,
was that really what you typed?  Because that's not a valid
import statement for the cgi module.  You should have done
"import cgi" instead.

2. If you really did "import cgi", and didn't get an error
at that instant, then the module really does exist and
can be imported.  In that case, typing "dir(cgi)" would
tell you what names were present in it.  That might give
you a hint as to the solution.

3. There's something strange about that traceback, I
think.  Why does it show the doc-string for the module,
and why does it show a comment after the "line 6" line?
Did you hand-edit this before posting it?

4. Standard library modules like cgi are written in pure
Python, so the source is right there on your machine.
Try "less /usr/lib/python2.3/" and spend some time
looking at that module, and see whether anything looks
fishy.  On my machine, for Python2.3, I see that
does a few imports, defines an "__all__" list which by
the way defines which symbols will be "exported" if you
do "from cgi import *", and then defines a bunch of
functions and classes, one of which is clearly FieldStorage.
Unless your Python installation is broken, I would think
you'd have the same and that the whole thing couldn't
really go wrong... it does look like strange behaviour,
but that's usually a sign that the solution will be
quite simple, maybe of the forehead-slapping kind.


More information about the Python-list mailing list