how to get a class instance name during creation?
gagsl-py2 at yahoo.com.ar
Fri Oct 3 22:27:44 CEST 2008
En Fri, 03 Oct 2008 15:04:01 -0300, dmitrey <dmitrey.kroshko at scipy.org>
> I have a code
> z = MyClass(some_args)
> can I somehow get info in MyClass __init__ function that user uses "z"
> as name of the variable?
> I.e. to have __init__ function that creates field z.name with value
No. I'd just write it as:
z = MyClass(some, args, 'z')
wich is pretty simple and readable (although you have to repeat the 'z').
All the alternative ways I know of require too much black magic.
More information about the Python-list