On Dec 4, 11:47 am, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Mon, 2007-12-03 at 18:27 -0800, hdante wrote: > > (note, you don't want to do this, it's a proof of concept) > > > import sys > > > class A(object): > > def __init__(self): > > pass > > def m1(self, x = None): > > if x == None: > > x = sys._getframe(1).f_locals > > ab = 'aB' > > x[ab].i = 10 > > del x[ab] > > print 'No more B' > > class B(object): > > def __init__(self, i): > > self.i = i > > def __del__(self): > > print 'delete B' > > > aA = A() > > aB = B(i = 6) > > print str(aB.i) > > aA.m1() > > print str(aB.i) > > That's not much of a proof of anything. It only works because the last > block happens to only use globals. If you stick it inside a function > with local names, it'll cease to "work". > > The bottom line is that you can not modify the namespace of the caller > within a function, unless you only use globals, and I hope I don't have
Namespace modification is used in ORMs, for example. The above example works in class definitions. I don't know why it doesn't work in functions. > to tell you what a fundamentally bad idea that is. > > My question to the OP is, what are you actually trying to accomplish? > > -- > Carsten Haesehttp://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list