> 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!
>
Awesome.
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,
On Wed, Jul 23, 2008 at 3:06 PM, Aaron Scott
<[EMAIL PROTECTED]> wrote:
> ... which is what I was expecting, but not what I want. Obviously,
> each import is creating its own instance of the variable. What I need
> is a way to change myvar from within "bar.py" so that PrintVar()
> returns the new v
> Just wirte test code !
variables.py:
myvar = 5
print myvar
foo.py:
from variables import *
def PrintVar():
print myvar
bar.py:
from variables import *
from foo import *
print myvar
myvar = 2
print myvar
PrintVar()
"python bar.py"
Aaron Scott schrieb:
> 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 ha