I do agree that it is a crazy format - and am amazed that it works at
the prompt.
For the first case - you have a mismatched double quote for test2 at
the end of the string. test2 should be r'c:\A\B;C\D;c:\program
files\xyz' instead. For the 2nd case - my code swallowed the ';' it
split on - so I
Its good to see what cpython did with the PATH. I now feel good about
taking the simple approach. It would be crazy if that sort of quoting
in the middle becomes something which works with too many applications
- and others are expected to keep up with it.
I guess I dont need to worry about unix
Michael Spencer wrote:
chirayuk wrote:
Hi,
I am trying to treat an environment variable as a python list - and
I'm
sure there must be a standard and simple way to do so. I know that
the
interpreter itself must use it (to process $PATH / %PATH%, etc) but
I
am not able to find a simple
if your goal is to search for files on a windows-style path environment
variable, maybe you don't want to take this approach, but instead wrap
and use the _wsearchenv or _searchenv C library functions
http://msdn.microsoft.com/library/en-us/vclib/html/_crt__searchenv.2c_._wsearchenv.asp
chirayuk wrote:
However, I just realized that the following is also a valid PATH in
windows.
PATH=c:\A\B;C\D;c:\program files\xyz
(The quotes do not need to cover the entire path)
Too bad! What a crazy format!
So here is my handcrafted solution.
def WinPathList_to_PyList (pathList):
pIter =
: Jeff Epler [mailto:[EMAIL PROTECTED]
Sent: Sunday, April 03, 2005 8:02 AM
To: chirayuk
Cc: python-list@python.org
Subject: Re: Corectly convert from %PATH%=c:\\X; c:\\a; b TO ['c:\\X',
'c:\\a; b']
if your goal is to search for files on a windows-style path environment
variable, maybe you don't want
The C code that Python uses to find the initial value of sys.path based
on PYTHONPATH seems to be simple splitting on the equivalent of
os.pathsep. See the source file Python/sysmodule.c, function
makepathobject().
for (i = 0; ; i++) {
p = strchr(path, delim); // ; on
Hi,
I am trying to treat an environment variable as a python list - and I'm
sure there must be a standard and simple way to do so. I know that the
interpreter itself must use it (to process $PATH / %PATH%, etc) but I
am not able to find a simple function to do so.
chirayuk wrote:
Hi,
I am trying to treat an environment variable as a python list - and I'm
sure there must be a standard and simple way to do so. I know that the
interpreter itself must use it (to process $PATH / %PATH%, etc) but I
am not able to find a simple function to do so.