[Tutor] How to find pythons: exceptions.py file
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Jan 15 17:00:19 EST 2004
On Thu, 15 Jan 2004, hcohen2 wrote:
> Did this:
>
> usr]$ find -name 'exceptions*' -print
> find: ./share/doc/printer-filters-1.0/EpsonEPL_L_Series/epl_docs:
> Permission denied
> ./lib/perl5/5.8.0/exceptions.pl
>
> well found the perl file - does python ver. 2.2.2 have such a file?
> Obviously exceptions are active as I have seen so often when I type the
> wrong code in or on testing my scripts!
Hello!
Some modules are statically compiled into the Python runtime. The
'exceptions' module,
http://www.python.org/doc/lib/module-exceptions.html
is one of them, so it doesn't correspond to a particular Python source
file:
###
>>> import exceptions
>>> exceptions.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute '__file__'
###
So for the 'exceptions' module, there's really no Python file that we can
point to.
However, the majority of the Standard Library is coded in Python:
###
>>> import difflib
>>> difflib.__file__
'/home/dyoo/local/Python-2.2.1/lib/python2.2/difflib.pyc'
>>> import copy
>>> copy.__file__
'/home/dyoo/local/Python-2.2.1/lib/python2.2/copy.pyc'
###
and from this, we can find that the Standard Library lives within
Python-2.2.1/lib/python2.2. A more systematic way to find the Standard
Library uses the distutils:
###
"""Quick program to print the directory where the Standard Library
lives."""
import distutils.sysconfig
print distutils.sysconfig.get_python_lib(standard_lib=1)
###
Hope this helps!
More information about the Tutor
mailing list