【发布时间】:2020-04-10 13:20:02
【问题描述】:
如何从我的主文件中打印我的 python 模块文件的文档字符串?假设我有一个名为 Projectile.py 的 python 模块文件,它在其中定义了一个名为 Projectile 的类。然后我有另一个名为 main.py 的 python 文件。在 main 中,我想访问模块级别的文档字符串。我该怎么做?
我知道如何打印类和方法的文档字符串。
例如,要从我的主文件中打印类级别的文档字符串,只需:
print(Projectile.__doc__)
Output: This is the class docstring: Simulates the flight of simple projectiles near the earth's surface, ignoring wind resistance. Tracking is done in two dimensions, height (y) and distance (x).
但是如何打印模块级别的文档字符串?谢谢!
"""This is the module docstring"""
from graphics import *
from math import *
class Projectile:
"""This is the class docstring: Simulates the flight of simple projectiles near the earth's surface,
ignoring wind resistance. Tracking is done in two dimensions, height (y) and distance (x)."""
# Constructor - TO INITIALIZE INSTANCE VARIABLES
"""This is the constructor docstring"""
def __init__(self, angle, velocity, height):
self.initialVelocity = velocity
self.xpos = 0.0
【问题讨论】: