property docstrings

Darren Dale dd55 at cornell.edu
Fri Mar 24 11:22:13 EST 2006


I am trying to work with properties, using python 2.4.2. I can't get the
docstrings to work, can someone suggest what I'm doing wrong? I think the
following script should print "This is the doc string.", but instead it
prints:

"float(x) -> floating point number

Convert a string or number to a floating point number, if possible."

Thanks,
Darren



class Example(object):
    _myattr = 0.0
    
    @apply
    def myattr():
        doc = """This is the doc string."""
        def fget(self):
            return self._myattr
        def fset(self, value):
            self._myattr = value
        def fdel(self):
            del self._myattr
        return property(**locals())
        
    _foo = 1.0
    def foo():
        doc = """This is the doc string."""
        def fget(self):
            """This is the doc string."""
            return self._foo
        def fset(self, value):
            """This is the doc string."""
            self._foo = value
        def fdel(self):
            """This is the doc string."""
            del self._foo
        return locals()
    foo = property(**foo())

    _bar = 1.0
    doc = """This is the doc string."""
    def get_bar(self):
        return self._bar
    def set_bar(self, value):
        self._bar = value
    def del_bar(self):
        del self._bar
    bar = property(get_bar, set_bar, del_bar, doc)

a=Example()
print 'myattr docstring:\n', a.myattr.__doc__
print 'foo docstring:\n', a.foo.__doc__
print 'bar docstring:\n', a.bar.__doc__




More information about the Python-list mailing list