listing all property variables of a class instance

André andre.roberge at gmail.com
Mon Jun 25 12:37:35 EDT 2007


Suppose I define a class with a number of variables defined as
properties.  Something like:

class MyClass(object):

    def __init__(self):
        self.some_variable = 42
        self._a = None
        self._b = "pi"

    def get_a(self):
        return self._a
    def set_a(self, value):
        self._a = value

    def get_b(self):
        return self._b
    def set_b(self, value):
        self._b = value

    a = property(get_a,  set_a, None, "a is a property")
    b = property(get_b,  set_b, None, "b is a property")

Is there a way to write a method that would list automatically all the
variables defined as a property (say by printing their docstring and/
or their value), and only those variables?

André




More information about the Python-list mailing list