[Catalog-sig] RE: Assistance with Python Classes

Lyle Johnson ljohnson@resgen.com
Wed, 18 Jul 2001 11:31:44 -0500

> Hi there can someone please assist me
> I am a perl programmer learning python. I keep on getting an exception =
> error:
> NameError: global name 'cgi' is not defined


I'm not sure how you ended up posting to this mailing list, but this kind of
question is really more appropriate for the general interest Python
newsgroup (comp.lang.python) or mailing list. In the future, please keep in
mind the purpose of the Catalog SIG when posting to this list. Having said
that, I think the problem with your script may be the placement of the
import statements and the attempt to create a "cgi" object when there is
none. Try this replacement for your WebManager module:

# Import these modules at the top level
import os
import cgi

class WebManager:
    def __init__(self):
        # FieldStorage() is a module method for the cgi module;
        # there is no cgi class to create.
        self.formdata = cgi.FieldStorage()
        self.operatingSys = os.name
    def getParam(self, name):
        if self.formdata.has_key(name):
            return self.formdata[name].value
            return None # not lowercase "none"!
    def getGenericInfo(self):
        return self.operatingSys

The Python reference documentation for the cgi module has some examples that
may help further.

Hope this helps,