listing attributes

Christoph Zwerschke cito at online.de
Tue Feb 14 07:04:22 EST 2006


Steven D'Aprano wrote:
 > However it is easy to use introspection to get what you need.

So just for completeness sake, what Thomas probably wants is the following:

from types import MethodType

def attributes(obj):
    return [attr for attr in dir(obj)
     if not attr.startswith('__')
     and not isinstance(getattr(obj, attr), MethodType)]

# Example:

class Parrot(object):
     ATTR = None
     join = ''.join # callable, but not a method of Parrot
     def aMethod(self):
         return ATTR

print attributes(Parrot)

# this gives: ['ATTR', 'join']



More information about the Python-list mailing list