我在Python 3中编写了一个程序,并使用Sphinx来记录它.Sphinx的autodoc很棒,但它只适用于Python 2.有些模块在autodoc中工作正常,但模块却没有.一些例子:Python 2抱怨Python 3样式元类,以及一些在Python 2中不再存在的模块,如configparser.这很烦人,因为它无法从该文件导入文档字符串.
我不想在Python 2中重写整个程序,但我想使用autodoc.
我有一个想法是一个小程序,它读取每个Python文件并删除所有功能,但只是将基本函数和类与其文档字符串一起离开(因为autodoc导入每个模块并读取特定函数或类的文档字符串).
import configparser
import os
class TestClass:
"""
I am a class docstring.
"""
def method(self, argument):
"""
I am a method docstring.
"""
#Some code here
print(os.getcwd())
def TestFunction():
"""
I am a function docstring.
"""
#Some more useless code here
return os.path.join("foo", "bar")
Run Code Online (Sandbox Code Playgroud)
成...
class TestClass:
"""
I am a class docstring.
"""
def method(self, argument):
"""
I am a method docstring.
"""
pass
def TestFunction():
"""
I …Run Code Online (Sandbox Code Playgroud)