How to Print the File Location of a Python Module

The are times were you may need to print the location of a python module. There are a number of ways to achieve this. However the most simplistic method  have found is to use 'inspect'.

Below shows you an a example,

>>> import inspect
>>> import urllib2
>>> print inspect.getfile(urllib2)

Tags: Python

About the Author


R Donato

Rick Donato is the Founder and Chief Editor of He currently works as an SDN/NFV Solutions Architect and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001