docstring

Inheriting methods' docstrings in Python

蹲街弑〆低调 提交于 2019-11-27 11:45:57
I have an OO hierarchy with docstrings that take as much maintenance as the code itself. E.g., class Swallow(object): def airspeed(self): """Returns the airspeed (unladen)""" raise NotImplementedError class AfricanSwallow(Swallow): def airspeed(self): # whatever Now, the problem is that AfricanSwallow.airspeed does not inherit the superclass method's docstring. I know I can keep the docstring using the template method pattern, i.e. class Swallow(object): def airspeed(self): """Returns the airspeed (unladen)""" return self._ask_arthur() and implementing _ask_arthur in each subclass. However, I

Using javadoc for Python documentation [closed]

核能气质少年 提交于 2019-11-27 09:57:24
I am currently beginning with Python and I have a strong PHP background and in PHP I have took the habit of using javadoc as a documentation template. I was wondering if javadoc has its place as docstring documentation in Python. What are the established conventions and/or official guildelines here? E.g. is something like this too elaborate to fit in the Python mindset or should I try to be as concise as possible? """ replaces template place holder with values @param string timestamp formatted date to display @param string priority priority number @param string priority_name priority name

How to document Python code with doxygen [closed]

不想你离开。 提交于 2019-11-27 09:18:48
问题 I like doxygen to create documentation of C or PHP code. I have an upcoming Python project and I think I remember that Python doesn't have /* .. */ comments, and also has its own self-documentation facility which seems to be the pythonic way to document. Since I'm familiar with doxygen, how can I use it to produce my Python documentation? Is there anything in particular that I need to be aware of? 回答1: This is documented on the doxygen website, but to summarize here: You can use doxygen to

print(__doc__) in Python 3 script

浪子不回头ぞ 提交于 2019-11-27 05:24:13
问题 I can't figure out what does the print(__doc__) do at the beginning of a script, like in this Scikit example. I have been looking for Python docstrings in google, and it seems __doc__ is useful to provide some documentation in, say, functions. But I can't see what does __doc__ do in the middle of a script. 回答1: it seems __doc__ is useful to provide some documentation in, say, functions This is true. In addition to functions, documentation can also be provided in modules. So, if you have a

Adding docstrings to namedtuples?

空扰寡人 提交于 2019-11-27 05:23:44
问题 Is it possible to add a documentation string to a namedtuple in an easy manner? I tried from collections import namedtuple Point = namedtuple("Point", ["x", "y"]) """ A point in 2D space """ # Yet another test """ A(nother) point in 2D space """ Point2 = namedtuple("Point2", ["x", "y"]) print Point.__doc__ # -> "Point(x, y)" print Point2.__doc__ # -> "Point2(x, y)" but that doesn't cut it. Is it possible to do in some other way? 回答1: You can achieve this by creating a simple, empty wrapper

How to document class attributes in Python? [closed]

独自空忆成欢 提交于 2019-11-27 05:19:06
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . I'm writing a lightweight class whose attributes are intended to be publicly accessible, and only sometimes overridden in specific instantiations. There's no provision in the Python language for creating docstrings for class attributes, or any sort of attributes, for that

“Expected an indented block” error?

假如想象 提交于 2019-11-27 03:09:07
问题 I can't understand why python gives an "Expected indentation block" error? """ This module prints all the items within a list""" def print_lol(the_list): """ The following for loop iterates over every item in the list and checks whether the list item is another list or not. in case the list item is another list it recalls the function else it prints the ist item""" for each_item in the_list: if isinstance(each_item, list): print_lol(each_item) else: print(each_item) 回答1: You have to indent

How to comment out a block of code in Python [duplicate]

折月煮酒 提交于 2019-11-26 22:28:23
问题 This question already has an answer here: Why doesn't Python have multiline comments? 17 answers Is there a mechanism to comment out large blocks of Python code? Right now, the only ways I can see of commenting out code are to either start every line with a # , or to enclose the code in triple quotes: """ . The problem with these is that inserting # before every line is cumbersome and """ makes the string I want to use as a comment show up in generated documentation. After reading all

How do I programmatically set the docstring?

故事扮演 提交于 2019-11-26 22:22:09
问题 I have a wrapper function that returns a function. Is there a way to programmatically set the docstring of the returned function? If I could write to __doc__ I'd do the following: def wrapper(a): def add_something(b): return a + b add_something.__doc__ = 'Adds ' + str(a) + ' to `b`' return add_something Then I could do >>> add_three = wrapper(3) >>> add_three.__doc__ 'Adds 3 to `b` However, since __doc__ is read-only, I can't do that. What's the correct way? Edit: Ok, I wanted to keep this

Inheriting methods' docstrings in Python

拜拜、爱过 提交于 2019-11-26 18:05:04
问题 I have an OO hierarchy with docstrings that take as much maintenance as the code itself. E.g., class Swallow(object): def airspeed(self): """Returns the airspeed (unladen)""" raise NotImplementedError class AfricanSwallow(Swallow): def airspeed(self): # whatever Now, the problem is that AfricanSwallow.airspeed does not inherit the superclass method's docstring. I know I can keep the docstring using the template method pattern, i.e. class Swallow(object): def airspeed(self): """Returns the