problem with global scope after package import via

Denis S. Otkidach ods at
Tue Aug 13 17:52:04 CEST 2002

On Tue, 13 Aug 2002, Mark Frazer wrote:

MF> I'd like to build a package out of several files as the
MF> individual files
MF> are large and become inwieldy.  Generally, I want a package
MF> user to
MF> import package
MF> only, and not worry about the individual files, so the
MF> for
MF> the package does
MF> from file import *
MF> for all the files in the package.
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?
#!/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

Denis S. Otkidach      [ru] [ru]

More information about the Python-list mailing list