Questions on importing and exec command.

Adrian Eyre a.eyre at optichrome.com
Fri Nov 5 08:51:08 EST 1999


> [snip]
>
> -------- call1.py -------
> for i in range(5,9):
>     print i
>     startit(hold_time=i)
> ---------------------------
>
> [snip]
>
> console > import call1           # importing a code fragment causes
problems
> 5
> exceptions.NameError startit

Although the test2.py script is aware of call1.py, the reverse is not true.
In order to use the 'startit' function in call1.py, it must be in its
namespace.

You can either put:

from test2 import startit

at the top of call1.py, or pass a reference to the function through to the
call1 module.

--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233  Fax: +44 1483 760 644
http://www.optichrome.com
--------------------------------------------





More information about the Python-list mailing list