473,394 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

property docstrings

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__

Mar 24 '06 #1
1 2003
Darren Dale wrote:
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
<snip>
a=Example()
print 'myattr docstring:\n', a.myattr.__doc__
print 'foo docstring:\n', a.foo.__doc__
print 'bar docstring:\n', a.bar.__doc__


change this part to:

print 'myattr docstring:\n', Example.myattr.__doc__
print 'foo docstring:\n', Example.foo.__doc__
print 'bar docstring:\n', Example.bar.__doc__

What happens is that when property is accessed
from an instance, it returns whatever the fget
function returns, and the __doc__ attribute
is then looked up on that object.

To get to the actual property object (and its
__doc__ attribute) you have to access it from
a class.

Ziga

Mar 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sridhar R | last post by:
When writing a python library, we can use docstrings for methods and functions that are part of API. But what about comments for non-API objects or python application code? For applications,...
0
by: Craig Ringer | last post by:
Hi folks I'm currently working on a fairly well internationalised app that embeds a Python intepreter. I'd like to make the docstrings translatable, but am running into the issue that the...
2
by: Steven Bethard | last post by:
I have two classes that implement the same interface, e.g. something like: class C(object): def foo(self): """Foo things""" ... def bar(self): """Bar things""" ... def baz(self):
0
by: Michael Muller | last post by:
I've observed something strange about property docstrings and I'm wondering if anyone here can clarify what's going on: if I create a class derived from property, the docstrings of the instances...
6
by: Kamilche | last post by:
I have a large project that is getting complex, and I would like to print the docstrings without importing the modules. The only Python utility I could find references is apparently defunct and...
0
by: Edward Loper | last post by:
Epydoc 3 supports extracting information about Python modules by parsing. As a result, it can extract "docstrings" for variables. There are several possible ways these docstrings could be...
4
by: Colin J. Williams | last post by:
Is there some way that the user can access the docstring specified for a property? Please see the example below: # propDocTest class A(object): def __init__(self, value): self.value= value...
1
bartonc
by: bartonc | last post by:
You will be rewarded sooner than you think when you use docstrings to document your classes and functions. Whether you ever intend to publish your work or not, docstrings will help you in several...
0
by: tjhnson | last post by:
The topic of docstrings for variables has come up many times before. In fact, a PEP was proposed and rejected on this very topic. http://www.python.org/dev/peps/pep-0224/ When creating...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.