473,385 Members | 1,720 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,385 software developers and data experts.

Getting the docstring of a property

How do you get the docstring of a property? Suppose I have the following:

class Foo:
def _prop_get(self):
return 1
prop = property(_prop_get, doc="This is the docstring")

foo = Foo()
print foo.prop
print foo.prop.__doc__

This will display "1", followed by the docstring for an integer (which
is the docstring for the int() function). How can I get the property's
docstring as defined in the property() function?
Jul 18 '05 #1
1 2063

"Andrew Durdin" <ad*****@gmail.com> wrote in message
news:ma**************************************@pyth on.org...
How do you get the docstring of a property? Suppose I have the following:

class Foo:
def _prop_get(self):
return 1
prop = property(_prop_get, doc="This is the docstring")

foo = Foo()
print foo.prop
print foo.prop.__doc__

This will display "1", followed by the docstring for an integer (which
is the docstring for the int() function). How can I get the property's
docstring as defined in the property() function?


You tried to access it from the instance. However, accessing it from the
instance invoked the property, returning 1, before it attempted to
access the docstring.

You need to get it from the class. That is:

Foo.prop.__doc__

should do what you want.

John Roth
Jul 18 '05 #2

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

Similar topics

0
by: Benoît Dejean | last post by:
does swig handle docstring ? i have written a C module using siwg, and i want to add some documentation using docstring. how can i do ?
0
by: Andrew Durdin | last post by:
I accidentally discovered that all the basic types in Python have docstrings that describe the functions to create them. For integers, you get: >>> (1).__doc__ 'int(x) -> integer\n\nConvert a...
7
by: Robert Ferber | last post by:
Hi, I can't find any good documentation about the Python-database module, all I found was this rudimentary (no examples, no references) piece here: http://www.python.org/peps/pep-0249.html ...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
3
by: Berthold Höllmann | last post by:
Saving the following code to a file and running the code through python does not give the expected error. disableling the "@decor" line leads to the expected error message. Is this a bug or an...
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...
0
by: paddy3118 | last post by:
Hello, I have just expanded the Wikipedia stub article on docstrings at http://en.wikipedia.org/wiki/Docstring. Unfortunately I do not know about Lisp, but took the time to google and found a...
1
by: jm.suresh | last post by:
In the following code, I could not find out why the set and get methods are not called once I set the property. .... def __init__(self): .... self._color = 12 .... def...
3
by: cyril giraudon | last post by:
Hello, I try to use python descriptors to define attributes with default value (the code is reported below). But apparently, it breaks the docstring mechanism. help(Basis) shows the right...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.