Re: ActiveState Python won't call module function
From: John Benson (jsbenson_at_bensonsystems.com)
Date: 11/29/03
- Next message: Peter Otten: "Re: list: from 2 to 3 dimensions..looking for a nice way"
- Previous message: sven: "list: from 2 to 3 dimensions..looking for a nice way"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 Nov 2003 13:39:11 -0800 To: <python-list@python.org>
"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 *"
- Next message: Peter Otten: "Re: list: from 2 to 3 dimensions..looking for a nice way"
- Previous message: sven: "list: from 2 to 3 dimensions..looking for a nice way"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|