En Thu, 01 Feb 2007 19:33:50 -0300, Gregory Piñero <[EMAIL PROTECTED]>  
escribió:

> I didn't realize Python behaved like this.  Is there an FAQ I can read  
> on this?
>
> FILE module1.py:
> VAR1='HI'
>
> FILE MAIN.py:
> from module1 import *
> import module1
>
> print VAR1
> print module1.VAR1
>
> VAR1='bye'
> print VAR1
> print module1.VAR1
>
> And the results are:
>
>>>> HI
> HI
> bye
> HI
>
> It seems to use module1.VAR1 for VAR1 until I assign something to VAR1
> in which case they become seperate.

There is no magic here. It's like this:

class Module: pass

module1 = Module()   # this is like `import module1`
module1.VAR1 = 'HI'

VAR1 = module1.VAR1  # this is like `from module1 import VAR1`

print VAR1
print module1.VAR1

VAR1='bye'
print VAR1
print module1.VAR1

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to