Find the path of a Python module

19/06/2009

The builtin inspect module makes it easy to find out information about the modules you are loading. Just ‘import inspect’ and use inspect.getfile

Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import inspect
>>> import random
>>> inspect.getfile(random)
‘c:\\Python26\\lib\\random.pyc’


Warning: count(): Parameter must be an array or an object that implements Countable in /home/public/blog/wp-includes/class-wp-comment-query.php on line 399

There is 1 comment in this article:

  1. 31/08/2009Aneesh say:

    Nice tip, Josh. This will come in handy for me, as my python modules are a messy conglomeration of easy_install-ed ones, unpacked tarballs, random locations added to the pythonpath.

Write a comment: