Information about including module?

B

bukzor

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
 
B

bukzor

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/Cookbook/Python/Recipe/473823
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top