469,327 Members | 1,323 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

site.here on python 2.4


greetings. it seems that the attribute site.here, of the site module,
has vanished in python 2.4. up until python 2.3, site.here seemed (to
me at least) a convenient way to get the complete path to the python
library on any platform:
import site
site.here

'/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3'

i do not see any information about this change save that in the new
documentation it says:

"""
This module is automatically imported during initialization. The
automatic import can be suppressed using the interpreter's -S option.

Importing this module will append site-specific paths to the module
search path.
"""

can anyone propose a similarly effective and cross-platform solution
for easily discovering the the library path on any python installation?

Jul 18 '05 #1
2 1352
"ariza" <ar***@flexatone.com> wrote:

greetings. it seems that the attribute site.here, of the site module,
has vanished in python 2.4. up until python 2.3, site.here seemed (to
me at least) a convenient way to get the complete path to the python
library on any platform.
"here" was a temporary variable used to get the exact location of
the LICENSE file. in Python 2.4, that code has been moved into
a function, in which "here" is still a temporary variable.

was it documented somewhere else?
can anyone propose a similarly effective and cross-platform solution
for easily discovering the the library path on any python installation?


the library path is defined by the sys.path variable, which contains a list
of library directories.

sys.prefix gives you the installation root, sys.executable tells you where
the interpreter is.

if you need the exact behaviour of "site.here", you can do

import os
here = os.path.dirname(os.__file__)

but I don't really see why your program should have to care about
anything but the path...

</F>

Jul 18 '05 #2

i am not sure where i found site.here documented as used prior to 2.4.

the issue is that i do not need sys.path, as in the list of all paths
that python searches. sys.prefix is close to what i need:
sys.prefix '/System/Library/Frameworks/Python.framework/Versions/2.3'

but the old site.here gave sys.prefix, plus the additional directories
to get into the actual python library:
site.here '/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3'

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'

this is useful for a few reasons. the first was i needed a cross
platform way to find the complete path to the idle directory; the
second was the complete path to the 'site-packages' directory.

thanks!

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by enrio | last post: by
1 post views Thread by Paul Ertz | last post: by
48 posts views Thread by northband | last post: by
1 post views Thread by michael.buonomo | last post: by
6 posts views Thread by Magdoll | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.