[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Information about including module?

bukzor

1/3/2008 12:53:00 AM

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
1 Answer

bukzor

1/3/2008 2:20:00 AM

0

On Jan 2, 4:52 pm, bukzor <workithar...@gmail.com> wrote:
> 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/Rec...