Getting a list of an object's methods?

Gerrit Holl gerrit at nl.linux.org
Sun Jun 22 16:32:24 EDT 2003


Jeremy Yallop wrote:
> Unfortunately, this isn't any better than the original idea of using
> dir(), since inspect.getmembers is implemented using dir().  As the OP
> noted, dir() isn't reliable.  For example, 'mro' isn't in int's dir(),
> although it is (the name of) a method of type and in type's __dict__.

Hm, how does readline does this? I use readline and I do get 'mro'
for an int when pressing tab:

22:31:11:2:gerrit at stopcontact:~$ python
Python 2.3b1+ (#3, Jun 19 2003, 10:34:37)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
  0 >>> int.
int.__abs__            int.__divmod__         int.__lshift__         int.__rand__           int.__rsub__
int.__add__            int.__doc__            int.__mod__            int.__rdiv__           int.__rtruediv__
int.__and__            int.__flags__          int.__module__         int.__rdivmod__        int.__rxor__
int.__base__           int.__float__          int.__mro__            int.__reduce__         int.__setattr__
int.__bases__          int.__floordiv__       int.__mul__            int.__reduce_ex__      int.__str__
int.__basicsize__      int.__getattribute__   int.__name__           int.__repr__           int.__sub__
int.__call__           int.__getnewargs__     int.__neg__            int.__rfloordiv__      int.__subclasses__
int.__class__          int.__hash__           int.__new__            int.__rlshift__        int.__truediv__
int.__cmp__            int.__hex__            int.__nonzero__        int.__rmod__           int.__weakrefoffset__
int.__coerce__         int.__init__           int.__oct__            int.__rmul__           int.__xor__
int.__delattr__        int.__int__            int.__or__             int.__ror__            int.mro
int.__dict__           int.__invert__         int.__pos__            int.__rpow__
int.__dictoffset__     int.__itemsize__       int.__pow__            int.__rrshift__
int.__div__            int.__long__           int.__radd__           int.__rshift__
  0 >>> readline.__file__
'/usr/local/lib/python2.3/lib-dynload/readline.so'

Readline appears to be implemented in C. Hmm...

yours,
Gerrit.

-- 
255. If he sublet the man's yoke of oxen or steal the seed-corn,
planting nothing in the field, he shall be convicted, and for each one
hundred gan he shall pay sixty gur of corn.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list