简体   繁体   English

Python:文档字符串未更新

[英]Python: Docstrings are not being updated

I have a docstring on the very first line of a Python file called a_file.py: 我在名为a_file.py的Python文件的第一行有一个文档字符串:

"""some text"""

When I print this using 当我使用

import a_file
print a_file.__doc__

it prints some text as exptected. 它会打印出some text预期的some text However, whenever I change the docstring to 但是,每当我将文档字符串更改为

"""different text"""

it still prints some text . 它仍然打印some text I have made sure the file was saved with the changes. 我确保文件已保存更改。 I have a feeling that there is something very simple that I am just overlooking. 我觉得有些事情我只是忽略了。 Any help would be greatly appreciated. 任何帮助将不胜感激。 I have read over the python page on docstrings but still no luck. 我已经阅读了有关docstringspython页面,但是仍然没有运气。

EDIT: SOLVED - I have figured it out. 编辑:解决了-我想通了。 Basically, I have a makefile which creates a new file. 基本上,我有一个makefile来创建一个新文件。 I was printing from the new file when I thought I was actually printing from the source file. 当我以为实际上是从源文件打印时,我正在从新文件打印。 When I re-ran the makefile with the edited text, all was well. 当我用编辑后的文本重新运行makefile时,一切都很好。

Are you editing the module's doctstring ? 您在编辑模块的doctstring吗? If so, you'll need to reimport the file as its docstring is now in the memory. 如果是这样,您将需要重新导入该文件,因为其文档字符串现在已在内存中。 Use reload for this If not, this code works: 为此使用reload ,否则,此代码有效:

>>> def a():
...     """ hello """
...     print 'aa'
... 
>>> a.__doc__
' hello '
>>> a.__doc__ = 'bla bla'
>>> a.__doc__
'bla bla'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM