How do I find out what file an import is using?

Robert Kern robert.kern at gmail.com
Wed May 9 14:10:54 EDT 2012


On 5/9/12 6:52 PM, Rob Richardson wrote:
> I am trying to work with a Python script someone else wrote.  The script includes the line
> 	from Level3Utils import *
>
> I need to look at the functions that are included in that import.  In an effort to identify exactly which file is being used, I renamed the Level3Utils.py and Level3Utils.pyc files in the same folder as the script I'm working on.  The import command in PythonWin executed without error.  I looked for a file named Level3Utils.py in my Python tree (d:/Python25, in my case).  None were there.  I then commented out the import line and stepped through the code.  It ran without error!  The class that should have come from Level3Utils executed successfully without being imported!
>
> How do I find out where the class definition actually is?
>
> (There is no PYTHONPATH environmental variable defined on my machine.)

import Level3Utils
print Level3Utils.__file__

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list