initializing private members via exec

Michael Hudson mwh at python.net
Fri Nov 16 05:36:51 EST 2001


Curtis Jensen <cjensen at bioeng.ucsd.edu> writes:

> Why session below give me an error? 

Because name mangling is done by the compiler, basically.

> Is there some rule against initializing private data members inside
> an exec function?  

(aside: "inside an exec function" suggests confusion)

Well, it doesn't work, does it?  So probably, yes.

> Is there an equivalant way of initializing private members?

exec 'self._Foo__monty = 1'?  Note the parentheses are an anachronism wrt
exec.

Not using double underscores?

Cheers,
M.

-- 
  This is the fixed point problem again; since all some implementors
  do is implement the compiler and libraries for compiler writing, the
  language becomes good at writing compilers and not much else!
                                 -- Brian Rogoff, comp.lang.functional



More information about the Python-list mailing list