Using variables across modules
Fredrik Lundh
fredrik at pythonware.com
Wed Jul 23 15:52:46 EDT 2008
Aaron Scott wrote:
> I'm having some trouble understanding how Python handles variables
> across multiple modules. I've dug through the documentation, but I
> still find myself at a loss.
>
> When you import a module, are you creating an instance of the
> variables within? For instance, if I have one file, "variables.py",
> which contains "myvar = 0", and I import it into both "foo.py" and
> "bar.py" with the line "from variables import *", and then set myvar
> in "foo.py" and "bar.py" to different values, will each file have a
> different value for myvar? If so, how can I ensure that a change to
> myvar in "bar.py" is reflected by "foo.py"? Or am I completely off
> base?
first read this to learn how objects and variables work in Python:
http://effbot.org/zone/python-objects.htm
and then read this to learn how from-import works, and when you're
supposed to use it:
http://effbot.org/zone/import-confusion.htm
hope this helps!
</F>
More information about the Python-list
mailing list