[英]How to get just summary line from python docstring?
I write test functions.我写测试函数。 In the docstring, I usually mention test case name as the summary line.
在文档字符串中,我通常提到测试用例名称作为摘要行。 The test case description follows that.
测试用例描述如下。 Now I just need to fetch the test case name (first line) from docstring.
现在我只需要从文档字符串中获取测试用例名称(第一行)。 Is there any pythonic way to do it?
有没有pythonic的方法来做到这一点?
def test_filesystem_001():
"""This is test case name of test_filesystem_001.
[Test Description]
-Create a file
-write some data
-delete it
"""
pass
So I need a way here just to print the first line of the docstring, ie, "This is test case name of test_filesystem_001."所以我需要一种方法来打印文档字符串的第一行,即“这是 test_filesystem_001 的测试用例名称”。 Thanks in advance.
提前致谢。
Just getting the first line:刚刚得到第一行:
>>>test_filesystem_001.__doc__.split("\n")[0]
This is test case name of test_filesystem_001.
You split
the __doc__
string at a new line.您
split
__doc__
字符串split
为新行。 This returns an array of the part before the new line and the part after the new line.这将返回新行之前的部分和新行之后的部分的数组。 To access the first part use
[0]
要访问第一部分,请使用
[0]
取文档字符串,将其分成几行,然后取第一个。
print test_filesystem_001.__doc__.splitlines()[0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.