problem with global scope after package import via __init__.py
Mark Frazer
mark at somanetworks.com
Tue Aug 13 11:54:52 EDT 2002
Denis S. Otkidach <ods at fep.ru> [02/08/13 11:51]:
> On Tue, 13 Aug 2002, Mark Frazer wrote:
>
> MF> However, there seems to be a problem accessing scalars when
> MF> the package
> MF> is imported in this fashion. The package files themselves
> MF> can access the
> MF> scalar properly, but the package user cannot. Is this a
> MF> bug?
>
> fail.py:
> #!/usr/bin/env python2
>
> import p
>
> val = 10
> p.set_a (val) # set p.a.aval to 10 (p.aval
> # has its original value)
>
> print "p.get_a() is ", p.get_a () # get p.a.aval
> assert p.get_a () == val # is OK
> print "p.aval is ", p.aval
> assert p.aval == val # is not OK since p.aval is
> # -999 (the value of p.a.aval
> # at the moment when a is
> # imported) and val is 10
Agreed. But, how do I access aval through the package? I don't want my
package users to know about the individual files in the package.
--
Professor, please, the fate of the world depends on you getting to second
base with Mom. - Fry
More information about the Python-list
mailing list