how to get a class instance name during creation?

Ben Finney bignose+hates-spam at
Sat Oct 4 11:16:35 CEST 2008

dmitrey <dmitrey.kroshko at> writes:

> On Oct 3, 9:46 pm, Bruno Desthuilliers
> <bdesth.quelquech... at> wrote:
> > 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
> range(100)].

You *know* this, *for sure*? The only way I can think of that would
give you such certain knowledge that such a situation will not happen
is an automated, full-coverage unit test suite of all code that uses
your class. Which is an excellent position to be in, so I commend you
on your diligence.

So, why is it that you wish to restrict users of your class to never
do such normal operations with instances as in the above examples?
What problem are you solving by this restriction?

 \                       “Holy human pressure cookers, Batman!” —Robin |
  `\                                                                   |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list