相关疑难解决方法(0)

模仿Python文档字符串

为什么动态格式化文档字符串不起作用?在功能定义时有没有可接受的解决方法?

>>> DEFAULT_BAR = "moe's tavern"
>>> def foo(bar=DEFAULT_BAR):
...     """
...     hello this is the docstring
...     
...     Args:
...       bar (str)    the bar argument (default: {})
...     """.format(DEFAULT_BAR)
... 
>>> foo.__doc__
>>> foo.__doc__ is None
True
Run Code Online (Sandbox Code Playgroud)

我尝试使用old-skool样式的%s格式,但也无法正常工作.

python docstring

4
推荐指数
1
解决办法
244
查看次数

标签 统计

docstring ×1

python ×1