To get all property of a class?

Egor Bolonev ebolonev at mail.ru
Mon Jun 30 01:14:20 CEST 2003


> Exist a sintax like
>
> import Foo
> for property in Foo
>     print property
>


for i in dir(a):
    if a[0] <>'_':
        print a;'=';a.i # isn't work, I don't know how to manage it - 'a.i'


      dir( [object])

Without arguments, return the list of names in the current local symbol
table. With an argument, attempts to return a list of valid attributes for
that object. This information is gleaned from the object's __dict__
attribute, if defined, and from the class or type object. The list is not
necessarily complete. If the object is a module object, the list contains
the names of the module's attributes. If the object is a type or class
object, the list contains the names of its attributes, and recursively of
the attributes of its bases. Otherwise, the list contains the object's
attributes' names, the names of its class's attributes, and recursively of
the attributes of its class's base classes. The resulting list is sorted
alphabetically. For example:

>>> import struct
>>> dir()
['__builtins__', '__doc__', '__name__', 'struct']
>>> dir(struct)
['__doc__', '__name__', 'calcsize', 'error', 'pack', 'unpack']

Note: Because dir() is supplied primarily as a convenience for use at an
interactive prompt, it tries to supply an interesting set of names more than
it tries to supply a rigorously or consistently defined set of names, and
its detailed behavior may change across releases.







More information about the Python-list mailing list