Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Getting a list of an object's methods?

Reply
Thread Tools

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

 
 
Jeremy Yallop
Guest
Posts: n/a
 
      06-23-2003
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Collections List : Converting from List '<Column <String1,String2>>' to 'List <String1>' asil klin Java 28 03-05-2011 01:59 AM
Memory issues when storing as List of Strings vs List of List OW Ghim Siong Python 2 11-30-2010 12:22 PM
Appending a list's elements to another list using a list comprehension Debajit Adhikary Python 17 10-18-2007 06:45 PM
Why does list.__getitem__ return a list instance for subclasses ofthe list type? dackz Python 0 02-06-2007 04:44 PM
Difference Between List x; and List x(); , if 'List' is a Class? roopa C++ 6 08-27-2004 06:18 PM



Advertisments