Re: How do I find out what file an import is using?
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I find out what file an import is using?
On 12-05-09 01: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! import Level3Utils Level3Utils.__file__ -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. IM: da...@vex.net -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I find out what file an import is using?
On 05/09/2012 01: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.) Thanks very much! RobR First, if you want to see the import path, just displaysys.path import sys print sys.path Next, it's bad practice to use the form:from import * because it's then hard to see what (if anything) you actually imported from there. And you can easily hide your own globals, or conversely hide some imports with a new global you might define. If removing the import doesn't stop the code from running, you probably aren't using anything from it, and should leave the line out. However, it is frequently useful to find where a module is coming from, and what symbols it defines. I'm using wxversion module for an example, because it's not very big. And I'm doing it interactively, while you probably want to print these values from your code. dir(wxversion) ['AlreadyImportedError', 'UPDATE_URL', 'VersionError', '_EM_DEBUG', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_find_default', '_find_installed', '_get_best_match', '_pattern', '_selected', '_wxPackageInfo', 'checkInstalled', 'ensureMinimal', 'fnmatch', 'getInstalled', 'glob', 'os', 're', 'select', 'sys'] wxversion.__file__ '/usr/lib/python2.7/dist-packages/wxversion.pyc' In other words, try print Level3Utils.__file__ -- DaveA -- http://mail.python.org/mailman/listinfo/python-list