为用户构建GUI以选择他们想要运行的Python脚本。每个脚本都有自己的文档字符串来解释脚本的输入和输出。我想在他们突出显示脚本后在UI中显示该信息,但没有选择运行该脚本,并且我似乎无法从基本程序访问文档字符串。 例如。 """this is a docstring"""
print('hello world') 是 对于本例,但通常是未知的,因为它是用户在GUI中选择的内容。 # index is test.py
def on_selected(self, index):
script_path = self.tree
在python项目中,我生成autoapi文档。特殊注释出现在生成的html文件中。例如,它正在最后的html页面上工作和显示:
def do_action(self,params):
"""
This is function to do some cool stuffs.
Actually it should
"""
pass
或
...
applicationConfig = None
"""This variable hold some important data"""
使用python的docstring与Sphinx Autodoc/拿破仑结合使用时,我遇到了一个奇怪的错误:
当使用docstring时,当我将注释放在参数上方时,格式就会中断。
"""
This yields in a wrongly formatted doc page.
:param chronic:
:type chronic:
"""
当我将文本放在参数后面(与pythons构建的文档字符串生成格式相反)时,它可以工作:
"""
:param chronic:
:type chronic:
The prints
我正在使用boost::python在c++代码中添加一个python模块。c++项目是用doxygen记录的。我想为python模块创建一个文档,但我不知道如何避免这样的冗余:
#include <boost/python.hpp>
using namespace boost::python;
/** @brief Sum two integers
* @param a an integer
* @param b another integer
* @return sum of integers
*/
int sum(int a, int b)
{
re
我想写一段代码,将docstring添加到Python函数中:
例如:
def foo(a):
b=a+1
return b
应生成以下内容
def foo(a):
"""One liner description
Parameters
----------
a : type
some comment
Returns
-------
b : type
some comment
"""
b=a+1
retu
我希望使用grep或awk从python文件中提取所有的docstring。我试过了
cat test.py | grep """[\w\W]*?"""
但我没看到输出。假设测试test.py看起来是这样的。
import libraries
class MyClass(object):
"""Docstring to this class.
second line of docstring."""
def myClassMethod(a,b):
我使用docopt模块来处理python脚本选项:
from docopt import docopt
"""Usage:
./convert [ -h | -i | -t | -c ]
Options:
-h Show this help
-i Convert image to vertical scroll box
-t Convert text to vertical scroll box
-c Convert command list to html
""
我有以下代码/文本:
def f():
"""
Return nothing.
.. NOTE::
First note line
second note line
在Emacs23 (23.4.1)中,我可以在最后一行(“第二个注释行”;不管该行是如何缩进的)中按Tab键,它可以像这样正确地对齐:
def f():
"""
Return nothing.
.. NOTE::
First note line
second note line
也
我在堆栈上搜索了我的问题,但没有找到解决方案,所以我来这里问你关于.im在python中学习的问题,在书'OReilly.Introducing.Python‘中,在模块部分的第5章中,.the作者说,当两个程序保存在一个目录中时,你可以保存一个程序并作为模块在另一个程序中使用。这是第一个使用as模块的程序。report.py
def get_description(): # see the docstring below?
"""Return random weather, just like the pros"""
from
我对python很陌生,问这个问题听起来很傻,但我想澄清一下。在学习过程中,我遇到了python允许作为多行注释和字符串文本的三元引号(“”)的代码,所以python如何知道它是作为注释还是字符串文本。
"""This
is treated
as comment
and ignored"""
a = """It is
treated as
string literal"""
print(a)
产出:-
It is
treated as
string literal
我看到VS代码从我在类函数中的注释中获得了intellisense提示:
def GyroDriveOnHeading(self, desiredHeading, desiredDistance):
"""
Drives the robot very straight on a given heading for a \
given distance, using the acceleration and the gyro. \
Accelerates to prevent wheel slipping. \
Gyro keeps
我目前正在为Python开发一个基于C++的模块。我发现Boost::Python可以很好地完成我想要完成的任务。但是,我现在遇到了一些由Boost::Python生成的文档字符串的问题。给定以下Boost::Python定义:
BOOST_PYTHON_MODULE(gcsmt)
{
class_<gcsmt::Units>("Units", "Sets the units used as input.", no_init)
.def("PrintSupported", &gcsmt::Units::printSup