how to get a class instance name during creation?

Gabriel Genellina gagsl-py2 at
Fri Oct 3 22:27:44 CEST 2008

En Fri, 03 Oct 2008 15:04:01 -0300, dmitrey <dmitrey.kroshko at>  

> 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 with value
> "z".

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.

Gabriel Genellina

More information about the Python-list mailing list