Reputation: 3102
When I try to run this code
"""Hello World"""
print globals()[__doc__]
Why do I get this error ?
Traceback (most recent call last):
File "D:\myProjects\python\Python-13.py", line 3, in <module>
print globals()[__doc__]
KeyError: 'Hello World'
Context : I just want the doc string of current module
Upvotes: 0
Views: 890
Reputation: 76876
The docstring of the current module is __doc__
. In your code you are trying to use that string as key in the global dictionary of the module.
To be clear, to print the docstring, just do print __doc__
.
Upvotes: 5