Newbie: problem with own module
Eric Brunel
eric.brunel at pragmadev.com
Thu Feb 20 04:07:21 EST 2003
Matthias Stern wrote:
> Hi! I have problems building my own modules. This is the a short version
> of the program with all functions (i show here only one) in one file:
>
> ---
> import WS
>
> def init(name):
> :
> WS.SetRunMode(1)
> :
>
> :
> :
>
> def main():
> init(something)
> main()
> ---
>
> Now I want to put all the functions like "init()" except main() into a
> module. this look like:
>
> module "boo.py":
>
> ---
> def init(name):
> :
> WS.SetRunMode(1)
> :
> ---
>
> main program:
>
> ---
>
> import WS
> import boo
>
> def main():
> boo.init(something)
> main()
> ---
>
> When I try to run this IDLE reports:
>
> File "<snip>\boo.py", line 12, in init
> WS.SetRunMode(1)
> NameError: global name 'WS' is not defined
>
>
> I tried to set a "import WS" command into file boo.py, too. But it didn't
> help. What am I doing wrong?
What was the problem exactly? Because it is actually the way to do it:
----boo.py----------
import WS
def init(name):
:
WS.SetRunMode(1)
:
--------------------
----main program----
import boo
def main():
boo.init(something)
main()
--------------------
This should work (provided that the WS.py module exists somewhere in your
PYTHONPATH). Can you please send the actual error you got? And where was your
file boo.py?
HTH
--
- Eric Brunel <eric.brunel at pragmadev.com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
More information about the Python-list
mailing list