【发布时间】:2018-04-08 21:41:03
【问题描述】:
我想使用 grep 或 awk 从我的 python 文件中提取所有文档字符串。 我试过了
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):
"""Docstring of the method.
another line in docstring of the method."""
return a + b
那么输出应该是用三引号括起来的所有内容。
"""Docstring to this class.
second line of docstring."""
"""Docstring of the method.
another line in docstring of the method."""
【问题讨论】:
-
我们需要更多细节,例如输入样本和预期输出。
-
我添加了测试用例并修正了错别字。