Finding the name of a class

2007-01-08 Thread tim mosher
Hello I'm looking for a Larry Bates that was in the Navy. Could this be you?? In CT in 1965??? In your 60's?? Please let me know I have been searching for over 10 yrs thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding the name of a class

2006-08-03 Thread John Salerno
Shane Hathaway wrote: > The bug is that the expression "dir(someclass)", where the class is a > user-defined class of either new or old style, never reveals to the user > that the class object has a __name__ attribute. I guess maybe it is a bug. This seems to be the relevant code to prove it:

Re: Finding the name of a class

2006-08-03 Thread Shane Hathaway
John Salerno wrote: > Shane Hathaway wrote: > >> Don't forget to file a bug. > > I'm reluctant to call it a bug just yet. Here's more stuff below. > There's obviously a difference between old- and new-style classes. It > seems that as far as new-style is concerned, __name__ is an attribute of

Re: Finding the name of a class

2006-08-02 Thread Kent Johnson
Kirk Strauser wrote: > Larry Bates wrote: > >> print print b.__class__.__name__ gives what you want > > That doesn't seem to do it, though. Here's the result of importing a module > from my company's internally-developed library: > from Daycos.TableCopier.copyfro import StateProcessor >>>

Re: Finding the name of a class

2006-08-02 Thread Bruno Desthuilliers
Larry Bates wrote: > Kirk Strauser wrote: >> Given a class: >> > class foo(object): > pass >> how can I find its name, such as: >> > b = foo > print something(b) >> 'foo' >> >> I'm writing a trace() decorator for the sake of practice, and am trying to >> print the name of the cl

Re: Finding the name of a class

2006-08-02 Thread Bruno Desthuilliers
Dennis Lee Bieber wrote: > On Tue, 01 Aug 2006 11:09:57 -0500, Kirk Strauser <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> Actually, I meant 'b = foo' in this case - I want to find the name of the >> class that b references, but the name of an instance (which may have zer

Re: Finding the name of a class

2006-08-02 Thread Bruno Desthuilliers
Kirk Strauser wrote: > Bruno Desthuilliers wrote: > >> Kirk Strauser wrote: > >> class foo(object): >> pass >>> how can I find its name, such as: >>> >> b = foo > >> I suppose you mean b = foo() ? > > Actually, I meant 'b = foo' in this case - I want to find the name of the > cl

Re: Finding the name of a class

2006-08-01 Thread bruno desthuilliers
Tim Chase a écrit : > class Foo(object): >> >> ... pass >> ... >> > b = Foo > b.__name__ >> >> 'Foo' > > > While this is surely true, would somebody explain why I had such trouble > finding this? Mmm... Documentation needs update ? > help(dir) > > Help on built-in functi

Re: Finding the name of a class

2006-08-01 Thread Larry Bates
Dennis Lee Bieber wrote: > On Tue, 01 Aug 2006 10:56:52 -0500, Kirk Strauser <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> Larry Bates wrote: >> >>> print print b.__class__.__name__ gives what you want >> That doesn't seem to do it, though. Here's the result of importin

Re: Finding the name of a class

2006-08-01 Thread Ziga Seilnacht
Kirk Strauser wrote: [snip] > OK, now for the good stuff. In the code below, how can I find the name of > the class that 'bar' belongs to: > > >>> class Foo(object): > ... def bar(self): > ... pass > ... > >>> b = Foo.bar >>> print b.im_class.__name__ Foo But if you are writing

Re: Finding the name of a class

2006-08-01 Thread John Salerno
Shane Hathaway wrote: > Don't forget to file a bug. I'm reluctant to call it a bug just yet. Here's more stuff below. There's obviously a difference between old- and new-style classes. It seems that as far as new-style is concerned, __name__ is an attribute of __class__ (along with a bunch of

Re: Finding the name of a class

2006-08-01 Thread Kirk Strauser
Bruno Desthuilliers wrote: > Kirk Strauser wrote: > class foo(object): > pass >> >> how can I find its name, such as: >> > b = foo > I suppose you mean b = foo() ? Actually, I meant 'b = foo' in this case - I want to find the name of the class that b references, but the name o

Re: Finding the name of a class

2006-08-01 Thread Shane Hathaway
John Salerno wrote: > >>> class Foo(object): > pass > > >>> dir(Foo) > ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', > '__hash__', '__init__', '__module__', '__new__', '__reduce__', > '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] > > Hmm

Re: Finding the name of a class

2006-08-01 Thread Tim Chase
>> While this is surely true, would somebody explain why I had such trouble >> finding this? > > I think __name__ is an attribute of the class itself, not the instance: That makes sense, but what doesn't make sense is why, when you do a dir(Foo), you don't get '__name__' in the returned list of

Re: Finding the name of a class

2006-08-01 Thread John Salerno
John Salerno wrote: > Tim Chase wrote: > >> While this is surely true, would somebody explain why I had such >> trouble finding this? > > I think __name__ is an attribute of the class itself, not the instance: On the other hand: >>> class Foo(object): pass >>> dir(Foo) ['__class__',

Re: Finding the name of a class

2006-08-01 Thread Kirk Strauser
Larry Bates wrote: > print print b.__class__.__name__ gives what you want That doesn't seem to do it, though. Here's the result of importing a module from my company's internally-developed library: >>> from Daycos.TableCopier.copyfro import StateProcessor >>> print StateProcessor.__class__.__n

Re: Finding the name of a class

2006-08-01 Thread John Salerno
Tim Chase wrote: > While this is surely true, would somebody explain why I had such trouble > finding this? I think __name__ is an attribute of the class itself, not the instance: >>> class Foo(object): pass >>> f = Foo() >>> f.__name__ Traceback (most recent call last): File ""

Re: Finding the name of a class

2006-08-01 Thread Tim Chase
class Foo(object): > ... pass > ... b = Foo b.__name__ > 'Foo' While this is surely true, would somebody explain why I had such trouble finding this? help(dir) > Help on built-in function dir in module __builtin__: continuing from your example... >>> dir(b) ['__class

Re: Finding the name of a class

2006-08-01 Thread Larry Bates
Kirk Strauser wrote: > Given a class: > class foo(object): pass > > how can I find its name, such as: > b = foo print something(b) > 'foo' > > I'm writing a trace() decorator for the sake of practice, and am trying to > print the name of the class that a traced method be

Re: Finding the name of a class

2006-08-01 Thread Bruno Desthuilliers
Kirk Strauser wrote: > Given a class: > class foo(object): pass > > how can I find its name, such as: > b = foo I suppose you mean b = foo() ? print something(b) > 'foo' The name of a class is in the attribute '__name__' of the class. The class of an object is in the a

Finding the name of a class

2006-08-01 Thread Kirk Strauser
Given a class: >>> class foo(object): >>> pass how can I find its name, such as: >>> b = foo >>> print something(b) 'foo' I'm writing a trace() decorator for the sake of practice, and am trying to print the name of the class that a traced method belongs to. This seems like it should be eas