[Tutor] how to determine where a module or function is called from

Lance Haig lnhaig at gmail.com
Thu Feb 22 23:32:08 CET 2007

Hi Kent,

Thank you

I was able to find it in the end.


It was at the bottom of the file I was editing



Kent Johnson wrote:
> Lance Haig wrote:
>> I am debugging a script that was written by someone else and I was 
>> wondering if there is a way to determine where a function or module 
>> is imported from
> You can use the __file__ attribute of a module:
> In [9]: csv.__file__
> Out[9]: 
> '/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/csv.pyc'
> For a function use the __module__ attribute to get the module:
> In [10]: csv.reader.__module__
> Out[10]: '_csv'
> This is a string so you have to do a little more work to get the file:
> In [12]: import sys
> In [13]: sys.modules[csv.reader.__module__].__file__
> Out[13]: 
> '/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/lib-dynload/_csv.so' 
> Kent

More information about the Tutor mailing list