how to get a class instance name during creation?
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Oct 3 16:27:44 EDT 2008
En Fri, 03 Oct 2008 15:04:01 -0300, dmitrey <dmitrey.kroshko at scipy.org>
escribió:
> 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
> "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