initializing private members via exec
Curtis Jensen
cjensen at bioeng.ucsd.edu
Thu Nov 15 13:32:46 EST 2001
Why session below give me an error? Is there some rule against
initializing private data members inside an exec function? Is there an
equivalant way of initializing private members? Thanks.
Python 1.5.2 (#4, Sep 5 2000, 10:29:12) [C] on irix646
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> class Foo:
... def __init__( self ):
... self.__bar = 0
... exec( 'self.barnone = 2' )
... exec( 'self.__monty = 3' )
... print 'bar:',self.__bar
... print 'barnone:',self.barnone
... print 'monty:',self.__monty
...
>>>
>>> jim = Foo()
bar: 0
barnone: 2
monty:
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "<stdin>", line 8, in __init__
AttributeError: _Foo__monty
--
Curtis Jensen
cjensen at bioeng.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451
More information about the Python-list
mailing list