Ha! I didn't realize that was getmembers' implementation. What a hack
;-)
In fact, your way is faster, since getmembers is taking the time to
sort its results (presumably so that repeated calls to the same object
will yield the same list; I don't think dir has a guaranteed ordering)
--
http://
> import inspect
> myCallables = [name for name, value in inspect.getmembers(self) if not
> name.startswith('_') and callable(value)]
Thanks. I forgot about the inspect module. Interestingly, you've also
answered my question more than I suspect you know! Check out the code
for inspect.getmember
Sion Arrowsmith wrote:
> Russell Warren <[EMAIL PROTECTED]> wrote:
(snip)
> At first I thought self.__dict__ would do it, but callable methods
>>seem to be excluded so I had to resort to dir, and deal with the
>>strings it gives me.
>
> This last sentence suggests to me something like:
>
> a
Russell Warren <[EMAIL PROTECTED]> wrote:
>Is there any better way to get a list of the public callables of self
>other than this?
>
>myCallables = []
>classDir = dir(self)
>for s in classDir:
> attr = self.__getattribute__(s)
> if callable(attr) and (not s.startswith("_")):
>
Russell Warren wrote:
> Is there any better way to get a list of the public callables of self
> other than this?
>
> myCallables = []
> classDir = dir(self)
> for s in classDir:
> attr = self.__getattribute__(s)
> if callable(attr) and (not s.startswith("_")):
> myC
import inspect
myCallables = [name for name, value in inspect.getmembers(self) if not
name.startswith('_') and callable(value)]
Instance methods aren't in self.__dict__ because they're a part of the
class. To made a comprehensive list of all the attributes available to
an instance, you have to t