name of object inside it's methods?

Michal Wallace (sabren) sabren at manifestation.com
Mon Feb 28 01:23:26 EST 2000


On Mon, 28 Feb 2000, Moshe Zadka wrote:

> On Mon, 28 Feb 2000, Jason Stokes wrote:
> 
> > 
> > >In other words I want the method to print the name of the object that it
> > >belongs to
> > 
> > 
> > Objects do not have names.  Objects can be referred to by names, but this is
> > not the same thing; any object can be referred to by multiple names.
> 
> Or none at all:
> 
> reader = lambda f=open("file"): f.readline()
> 
> The file isn't referred to with any name you can get your hands on easily.
> (Yes, you could start taking reader apart, but it's at best shaky)


Hmmm.... On third thought, there are several ways you can "sort of"
get the name(s) of an object, if you're willing to be flexible, (or in
the first case, just plain nuts):

A) you could recursively loop through all the namespaces
   available to your program and do an "is" check against
   everything you find.... 

B) you could give the object a .Name attribute and just
   use that instead. :)


I'm sure there are other ways to fill out that list..

Cheers,

- Michal
-------------------------------------------------------------------------
http://www.manifestation.com/         http://www.linkwatcher.com/metalog/
-------------------------------------------------------------------------





More information about the Python-list mailing list