Re: Getting a list of an object's methods?

Discussion in 'Python' started by Jeremy Yallop, Jun 23, 2003.

  1. Gerrit Holl wrote:
    > 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:

    [snip]
    > Readline appears to be implemented in C. Hmm...


    Readline is indeed implemented in C, but the function which completes
    the partial member names is written in Python: see the Completer class
    in the rlcompleter module. The actual implementation is rather
    simple: it calls dir on the instance, its class and (recursively) its
    class's bases.

    The code is fairly straightforward and might at least give the OP some
    ideas.

    Jeremy.
     
    Jeremy Yallop, Jun 23, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Yallop

    Re: Getting a list of an object's methods?

    Jeremy Yallop, Jun 23, 2003, in forum: Python
    Replies:
    1
    Views:
    1,356
    Freddie
    Jun 23, 2003
  2. Michele Simionato

    Re: Getting a list of an object's methods?

    Michele Simionato, Jun 24, 2003, in forum: Python
    Replies:
    0
    Views:
    643
    Michele Simionato
    Jun 24, 2003
  3. DG
    Replies:
    3
    Views:
    348
    Terry Reedy
    Jul 22, 2009
  4. Nikita Petrov
    Replies:
    2
    Views:
    131
    Gary Wright
    Apr 6, 2008
  5. Kenneth McDonald
    Replies:
    5
    Views:
    386
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page