problem with global scope after package import via __init__.py

Denis S. Otkidach ods at fep.ru
Tue Aug 13 18:00:40 CEST 2002


On Tue, 13 Aug 2002, Mark Frazer wrote:

MF> > import p
MF> >
MF> > val = 10
MF> > p.set_a (val)                     # set p.a.aval to 10
MF> (p.aval
MF> >                                   # has its original
MF> value)
MF> >
MF> > print "p.get_a() is ", p.get_a () # get p.a.aval
MF> > assert p.get_a () == val          # is OK
MF> > print "p.aval is ", p.aval
MF> > assert p.aval == val              # is not OK since p.aval
MF> is
MF> >                                   # -999 (the value of
MF> p.a.aval
MF> >                                   # at the moment when a
MF> is
MF> >                                   # imported) and val is
MF> 10
MF>
MF> Agreed.  But, how do I access aval through the package?  I
MF> don't want my
MF> package users to know about the individual files in the
MF> package.

Make aval private (rename to _aval - it won't be imported with
"from ... import *") and let users access it via {get|set}_a()
functions only.

-- 
Denis S. Otkidach
http://www.python.ru/      [ru]
http://diveinto.python.ru/ [ru]





More information about the Python-list mailing list