469,364 Members | 2,332 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

Information about including module?

Is there any way to print the docstring of the including module? I'd
like to be able to do something like the following
file one.py:

"some docstring"
include two
file two.py:
from magicmodule import getincluder
print getincluder().__doc__
Running one.py would print the docstring.

Thanks!
Buck
Jan 3 '08 #1
1 941
On Jan 2, 4:52 pm, bukzor <workithar...@gmail.comwrote:
Is there any way to print the docstring of the including module? I'd
like to be able to do something like the following

file one.py:

"some docstring"
include two

file two.py:
from magicmodule import getincluder
print getincluder().__doc__

Running one.py would print the docstring.

Thanks!
Buck

Answered my own question:

def getimporter():
from inspect import stack
for info in stack():
text = info[4][0].split()
if 'import' in text and text[0] in ('from', 'import'):
return info[0].f_locals
print getimporter()['__doc__']
This is a simplified version of the recipe here:
http://aspn.activestate.com/ASPN/Coo.../Recipe/473823
Jan 3 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Rene Olsthoorn | last post: by
4 posts views Thread by Mudcat | last post: by
reply views Thread by Paul Bromley | last post: by
27 posts views Thread by matt | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.