我使用python编写了一个相对简单的脚本,并为所有方法编写了doc字符串,如下所示:

def processData(rawData):
    """Proccessing raw data from weather station using Regex to get final sensor readings.

    Args:
        rawData: A string contains all the sensor readings. This string will be processed
                 using regex to remove garbage.

    Returns:
        finalList: A list of final sensor readings."""

但是,当我试图通过解释器打印doc字符串时,doc字符串被打印为“None”
>>> import ws100_weather_data as weather
>>> print weather.__doc__
None

但是帮助(天气)显示所有的文档字符串以及其他信息。我在这里做错什么了吗?如果是,那么访问doc字符串的正确方法是什么?
谢谢您。

最佳答案

不同的对象有不同的文档字符串。函数的docstring是processData.__doc__,模块的docstring是weather.__doc__,您没有定义它。将其定义为文件顶部全局作用域中的裸字符串(未分配)。

关于python - python:__doc__ doc trings显示为none,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7253018/

10-12 18:59