how to get a class instance name during creation?
dmitrey.kroshko at scipy.org
Sat Oct 4 10:02:01 CEST 2008
On Oct 3, 9:46 pm, Bruno Desthuilliers
<bdesth.quelquech... at free.quelquepart.fr> wrote:
> dmitrey a écrit :
> > hi all,
> > 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".
> This has been debated to hell and back. To make a long story short, here
> are two common use cases:
> x = MyClass()
> y = x
> del x
> objects = [MyClass() for i in range(100)]
> If you can come with a meaningfull answer to "what's *the* name of any
> of the MyClass instance(s)" in both cases, then please let us know...
I had seen the examples during google search, still I hoped for an
answer to my exact situation. I know for sure there will be no
renaming and creating like the above objects = [MyClass() for i in
as for the z = MyClass(some, args, 'z') I had it in my mind but I
hoped to have something automatic, w/o the arg 'z'.
More information about the Python-list