2
我試圖做一個文檔字符串,將接受替代字段如下我可以格式化文檔字符串中python3
def run_tests(args):
"""run tests on methods in {0}
usage: {0} --tests
""".format(__file__)
pass
,但是當我在解釋器中運行help(run_tests)
,我沒有得到的文檔字符串。如果我刪除{}和.format(),則文檔字符串按預期返回。
我想看到的輸出是這樣的:
Help on function run_tests in module myfile:
run_tests(args)
runs tests on methods in myfile.py
usage: myfile.py --tests
有沒有辦法在python3做到這一點?
既不適用於Python的2;請參閱https://stackoverflow.com/questions/36705130/python-docstrings-templated for solution – abukaj