Imports in python are static, any solution?
David Stanek
dstanek at dstanek.com
Mon Apr 13 12:11:45 EDT 2009
On Mon, Apr 13, 2009 at 11:59 AM, Ravi <ra.ravi.rav at gmail.com> wrote:
> foo.py :
>
> i = 10
>
> def fi():
> global i
> i = 99
>
> bar.py :
>
> import foo
> from foo import i
>
> print i, foo.i
> foo.fi()
> print i, foo.i
>
> This is problematic. Well I want i to change with foo.fi() .
Why not only import foo and using foo.i? In fi() when you set i = 99
you are creating a new object called i in foo's namespace.
--
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
More information about the Python-list
mailing list