fir3net
PPS-Firenetbanner-780.5x190-30-03-17

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)
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.pyc

Tags: Python

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001