newbie: from .. import *

James Rowe jimrowe at optilink.com
Thu Jun 13 18:40:52 EDT 2002


On 13 Jun 2002 15:37:38 -0700, Jean-Sébastien Bolduc <jseb at cs.mcgill.ca> wrote:
>Hi All
>
>I've been working with Python for a while, but never really felt
>confortable with the way namespaces are imported.
>
>I'm working on a simple application that is to be used in the
>interactive mode. The idea is that the behavior of a function is
>determined, in part, by some global(?) flags. So I can change my
>flags, and explicitely call my function. Really simple. Except that
>for some reason, it does not work.
>
>In "test.py", I have the following:
>
>  flag = 1
>  def foo():
>    print flag
>  foo()
>  flag = 0
>  foo()
>  
>In the interactive mode, if I import the code above as:
>>>> from test import *
>1
>0
>
>The output is as expected. However, if I continue:
>>>> flag = 1
>>>> foo()
>0
>

# bar.py

flag = 1
def foo():
   print flag
foo()
flag = 2
foo()


>>> from bar import *
1
2
>>> import bar
>>> foo()
2
>>> flag = 3
>>> foo()
2
>>> bar.flag = 4
>>> foo()
4





More information about the Python-list mailing list