docstring

What is the best way in python to write docstrings for lambda functions?

让人想犯罪 __ 提交于 2021-02-20 18:52:26
问题 I usually comment my functions using multi-line docstrings with """, as mentioned in : https://www.python.org/dev/peps/pep-0257/ def func1(x): """ This function does ... """ ... But what is the best way to comment a lambda function ? I hesitate between : # This function does ... func2 = lambda x: ... or : func2 = lambda x: ... """ This function does ... """ or else ? 回答1: tbh, even assigning a lambda to a variable seems unpythonic to me. if it needs a name, define it as a regular function.

Is it possible embed pictures into docstring in Python?

我怕爱的太早我们不能终老 提交于 2021-02-19 10:14:36
问题 Is it possible embed pictures into docstring in Python? I saw docpicture keyword somewhere, but can't find doc on it. Is it stabdartized or not? Where does picture should located? UPDATE I tried Sphinx notation, but my PyCharm shows i.e. it sees that it should be an image here, but doesn't see image file. Where I would put if used Sphinx? 回答1: That depends on what tool you use for processing your docstring. Check your tool's documentation to find out how to embed images. For example, if you

Sphinx autodoc functions within module

半腔热情 提交于 2021-02-18 12:42:14
问题 I am just getting started with sphinx and willing to learn. I would like to break up my various functions into different sections within my index.rst file. So each function has it's own header. So for example if I have a python file named test.py and within that file I have 2 functions: def foo(): """This prints bar""" print("bar") def bar(): """This prints foo""" print("foo") How could I within the index.rst separate the 2 functions within my test.py file? :mod:`test` -- foo .. automodule::

Including a docstring in another docstring

眉间皱痕 提交于 2021-02-08 12:06:21
问题 Problem: I want to use one docstring in another docstring. Suppose I have the following snippet: def window(dimensions: tuple): ''' Function to create an app window and return it PARAMETERS ---------- dimensions : tuple The width and height of the window to create RETURNS ------- display.Window Class to implement a screen # Make this equal to Window.__doc__ ''' class Window: ''' Class to implement a screen ''' def __init__(self, dimensions: tuple): pass return Window(dimensions) I want to

Including a docstring in another docstring

怎甘沉沦 提交于 2021-02-08 12:05:44
问题 Problem: I want to use one docstring in another docstring. Suppose I have the following snippet: def window(dimensions: tuple): ''' Function to create an app window and return it PARAMETERS ---------- dimensions : tuple The width and height of the window to create RETURNS ------- display.Window Class to implement a screen # Make this equal to Window.__doc__ ''' class Window: ''' Class to implement a screen ''' def __init__(self, dimensions: tuple): pass return Window(dimensions) I want to

Using Python docstring override and extend verbs in Sphinx

时光总嘲笑我的痴心妄想 提交于 2021-02-08 09:46:11
问题 I am using Sphinx to generate documentation from my docstrings, which are formatted in the Sphinx style. According to PEP-257 I should be using the verb "override" and "extend" to indicate if inherited methods are replaced or called. If a class subclasses another class and its behavior is mostly inherited from that class, its docstring should mention this and summarize the differences. Use the verb "override" to indicate that a subclass method replaces a superclass method and does not call

Python dynamic help and autocomplete generation

柔情痞子 提交于 2021-02-08 03:39:26
问题 I have almost what I want... This dynamic object encapsulating a generic function call with a dynamic docstring generation: def add_docs(tool): def desc(func): func.__doc__ = "Showing help for %s()" % tool return func return desc class Dynamic(object): def __getattr__(self, value): @add_docs(value) def mutable_f(*args, **kwargs): print "Calling:", value print "With arguments:", args, kwargs return mutable_f And it works as expected: >>> Dynamic().test(1, input='file') Calling: test With

Is there a docstring autocompletion tool for jupyter notebook?

99封情书 提交于 2021-02-07 07:01:23
问题 I am looking for a tool/extension that helps you writing python docstrings in jupyter notebook. I normally use VS code where you have the autodocstring extension that automatically generates templates (e.g. the sphinx or numpy template) for docstrings. Is there an equivalent to this in jupyter notebook? I have been looking online for a long time now, but have trouble finding it. 回答1: run this in a Notebook cell: %config IPCompleter.greedy=True Then press tab where you want to do autocomplete.

Repetitive content in docstrings

非 Y 不嫁゛ 提交于 2020-12-29 13:16:58
问题 What are good ways to deal with repetitive content in docstrings? I have many functions that take 'standard' arguments, which have to be explained in the docstring, but it would be nice to write the relevant parts of the docstring only once, as this would be much easier to maintain and update. I naively tried the following: arg_a = "a: a very common argument" def test(a): ''' Arguments: %s ''' % arg_a pass But this does not work, because when I do help(test) I don't see the docstring. Is

Repetitive content in docstrings

牧云@^-^@ 提交于 2020-12-29 13:16:05
问题 What are good ways to deal with repetitive content in docstrings? I have many functions that take 'standard' arguments, which have to be explained in the docstring, but it would be nice to write the relevant parts of the docstring only once, as this would be much easier to maintain and update. I naively tried the following: arg_a = "a: a very common argument" def test(a): ''' Arguments: %s ''' % arg_a pass But this does not work, because when I do help(test) I don't see the docstring. Is