ActiveState Python won't call module function

John Benson jsbenson at bensonsystems.com
Sat Nov 29 16:39:11 EST 2003


"import" in the following makes x but not y a global, so y must be qualified
in the importing module:

import module x
...
    z = x.y()

where x is the imported module, y is a class in module x, and z is the
reference to the new instance of y

In your case,

thisClass = module1.module2()

should solve the problem.

Another way to do it is using the "from" statement which adds the module's
globals to your globals:

from x import y
...
    z = y()

or, worse,

from x import *
...
    z = y()

but the documentation cautions against wholesale importation of module names
into the caller's namespace unless the imported module has been designed
specifically for it (e.g. Tkinter). Purists rebel against even this usage of
"from ... import *"







More information about the Python-list mailing list