Adding paths to sys.path permanently, and another problem...
jeff at ccvcorp.com
Thu Dec 16 23:54:44 CET 2004
Amir Dekel wrote:
> 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
Well, according to os.path.expanduser()'s docstring, it uses the $HOME
environment variable to determine how to expand ~. I don't know what's
standard on Windows, but I tried checking for a $HOME and found none.
Here's (a slightly redacted copy of) what I *do* find (Win2K):
>>> for key, val in os.environ.items():
... print '%15s %s' % (key, val)
COMMONPROGRAMFILES C:\Program Files\Common Files
PROCESSOR_IDENTIFIER x86 Family #...
PROGRAMFILES C:\Program Files
APPDATA C:\Documents and Settings\Jeff\Application Data
ALLUSERSPROFILE C:\Documents and Settings\All Users.WINNT
USERPROFILE C:\Documents and Settings\Jeff
Judging from this, I think that os.environ['USERPROFILE'] seems like it
may do what you want, though os.environ['APPDATA'] might be useful as
well. Of course, if you're trying to get something to work
cross-platform, things may be more difficult -- but that's because
Windows doesn't normally use ~ so its use is not supported very well.
You may be able to create a $HOME that's equivalent to $USERPROFILE...
More information about the Python-list