namespace question
7stud
bbxx789_05ss at yahoo.com
Fri May 18 15:54:46 EDT 2007
On May 18, 12:29 pm, "T. Crane" <tcr... at REMOVETHISuiuc.edu> wrote:
> If you put them at the top level, and suppose you saved it all in a file
> called test.py, then when you type
>
> ln [1]: from test import myClass
>
> does it still load a,b,c and numpy into the namespace?
>
Yep. Easy to test:
toBeImported.py
-----------------
1) Create a global variable: x = "red"
2) Create a function or a class with a method that prints out the
value of x.
yourProgram.py
--------------
1) Create a global variable with the same name, but with a different
value: x = 100
2) Use from...import to import your class or function
3) Call the method or function that displays x. Which value for x was
displayed?
When things defined in a module travel around, they carry a snapshot
of home with them.
More information about the Python-list
mailing list