Finding the name of a class
Tim Chase
python.list at tim.thechases.com
Tue Aug 1 11:54:32 EDT 2006
>>>> 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__', '__delattr__', '__dict__', '__doc__',
'__getattribute__', '__hash__', '__init__', '__module__',
'__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__', '__weakref__']
>>> '__name__' in dir(b)
False
'__name__' *really is* a method of b as shown by your example
lines, and can be successfully called. However, it *doesn't*
show up when asked for via dir(b). Grumble.
Is there a dir_and_i_really_mean_everything() function?
I suppose problems (mostly with expectations) can ensue when
you've got dynamic attributes, but this seems like something that
dir() should be finding.
-a puzzled tkc
More information about the Python-list
mailing list