Adding paths to sys.path permanently, and another problem...
fperez528 at yahoo.com
Fri Dec 17 01:35:22 CET 2004
Amir Dekel wrote:
> Hi everyone,
> I have two problems:
> 1. How can I keep my changes in sys.path after closing the interpreter?
As others said, use $PYTHONPATH
> 2. os.path.expanduser("~") always gives me "C:\\" instead of my
> homepath. I have tried to change my homepath in WinXP using set
> homepath(in command line), and alsaw using the "Environment Variables"
> in WinXP system properties, non helped. I really have to fix this somehow.
This is what ipython uses to try and get that information in a portable manner.
Note that it uses _winreg, which is part of the win32 extensions.
In : import IPython.genutils
In : psource IPython.genutils.get_home_dir
"""Return the closest possible equivalent to a 'home' directory.
For Posix systems, this is $HOME, and on NT it's $HOMEDRIVE\$HOMEPATH.
Currently only Posix and NT are implemented, a HomeDirError exception is
raised for all other OSes. """ #'
if os.name == 'posix':
elif os.name == 'nt':
# For some strange reason, win9x returns 'nt' for os.name.
# Use the registry to get the 'My Documents' folder.
import _winreg as wreg
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
homedir = wreg.QueryValueEx(key,'Personal')
elif os.name == 'dos':
# Desperate, may do absurd things in classic MacOS. May work under DOS.
raise HomeDirError,'support for your operating system not implemented.'
More information about the Python-list