Getting a list of an object's methods?
Freddie
oinkfreddie at oinkmadcowdisease.oinkorg
Mon Jun 23 17:50:11 EDT 2003
Jeremy Yallop <jeremy at jdyallop.freeserve.co.uk> wrote in
news:bd7qdu$pkgc5$2 at ID-114079.news.dfncis.de:
> Alexander Schmolck wrote:
>> The premises are right, but they don't entail the conclusion. `dir`s
>> behavior is not guaranteed to be stable, but `inspect.getmembers`'s
>> obviously is [1].
>
> [further logic and "obvious" things snuipped]
>
> All very well, but inspect.getmembers is implemented using dir() /now/,
> and doesn't return all of the methods in the /currently-existing/
> versions of Python that the OP wants to use. It isn't an appropriate
> solution, unfortunately.
>
>> I don't think "What methods does this object have?" is a question
>> that only a python wizard should be able to ask and receive a
>> well-defined answer.
>
> Well, that's certainly true.
>
> Jeremy.
>
The dir(self.__class__) works OK for me, since they're all wacky custom
classes. I would still like to know why, in Python 2.1, none of the methods
show up for when using dir() (or __dict__) on an instance of the class. It's
really quite odd :)
>>> len(dir(blah)), len(dir(blah.__dict__))
(24, 24)
>>> len(dir(blah.__class__)), len(dir(blah.__class__.__dict__))
(49, 49)
Thanks to the various people who helped me out again :)
Freddie
--------------------------------------------------------------
Remove the z's from my e-mail address if you really want to
More information about the Python-list
mailing list