Find the path of a Python module


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)

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: