Finding the public callables of self

Russell Warren russandheather at gmail.com
Thu Feb 9 11:07:11 EST 2006


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("_")):
        myCallables.append(s) #collect the names (not funcs)

I don't mean a shorter list comprehension or something that just drops
the line count, but whether or not I need to go at it through dir and
__getattribute__.  This seems a bit convoluted and with python it often
seems there's something already canned to do stuff like this when I do
it.  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.

Thanks,
Russ




More information about the Python-list mailing list