site.here on python 2.4

Tony Meyer t-meyer at ihug.co.nz
Thu Jan 13 15:15:28 EST 2005


> can we assume that, on all platforms, the old site.here is 
> the same as:
> 
> >>> os.path.join(sys.prefix, 'lib', 'python%s' % sys.version[:3])
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3'
> 
> or is it better to use, as you suggest,
> 
> >>> import os
> >>> os.path.dirname(os.__file__)
> '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3'

These are not the same on Windows:

>>> os.path.join(sys.prefix, 'lib', 'python%s' % sys.version[:3])
'c:\\python24\\lib\\python2.4'
>>> os.path.dirname(os.__file__)
'c:\\python24\\lib'

(The latter is correct, if you want the directory that site-packages and
idlelib are in.

(And, for reference, with Python 2.3:
>>> site.here
'c:\\python23\\lib'
)

=Tony.Meyer




More information about the Python-list mailing list