[Python-bugs-list] [ python-Bugs-824371 ] ntpath.expandvars doesn't expand Windows-style variables.

SourceForge.net noreply at sourceforge.net
Sun Nov 2 12:56:57 EST 2003

Bugs item #824371, was opened at 2003-10-15 22:32
Message generated for change (Comment added) made by aleax
You can respond by visiting: 

>Category: Windows
>Group: Feature Request
Status: Open
Resolution: None
>Priority: 4
Submitted By: Jeremy Fincher (jemfinch)
Assigned to: Nobody/Anonymous (nobody)
Summary: ntpath.expandvars doesn't expand Windows-style variables.

Initial Comment:
ntpath.expandvars is exactly the same as
posixpath.expandvars -- it only expands $vars.  But in
windows, environment variables are represented by
%vars%, not $vars.

I can write a patch if necessary.  Having read the
code, I noticed that it went to great lengths to do
what could quite easily be done with a regular
expression, so I assume using regular expressions isn't
kosher in the *path modules?


>Comment By: Alex Martelli (aleax)
Date: 2003-11-02 18:56

Logged In: YES 

it seems to me that the behavior of os.path.expandvars is clearly documented (both in the docstrings and the library reference) and therefore i marked this as a feature request with slightly lower priority (features are unlikely to be added within 2.3 any more -- you may want to target 2.4 for this, therefore).


Comment By: Johan M. Hahn (johahn)
Date: 2003-10-20 20:26

Logged In: YES 

Hi Jeremy

   The purpose of path.expandvars is to retrieve environment 
variables in a platform independant way into a user supplied 
string, as in path.expandvars('$PYTHON/Lib/site-packages'). 
Using %vars% on windows and $vars on unix would make the 
method pointless. So this is no bug, though it might be 
explained a little vague in the docstring (IMHO the overall 
purpose and the phrase "left unchanged" are both unclear):

>>> help(path.expandvars)

Help on function expandvars in module ntpath:


    Expand shell variables of form $var and ${var}.

    Unknown variables are left unchanged.

   Though, the module docs offer a better explanation:

"Return the argument with environment variables expanded. 
Substrings of the form "$name" or "${name}" are replaced by 
the value of environment variable name. Malformed variable 
names and references to non-existing variables are left 
unchanged. On the Macintosh, this always returns path 

   Still, what does "unchanged" mean? On my windows system 
non-existing variables are IGNORED, they are not left 
unchanged anywhere:

>>> path.expandvars('$MADEUP/Lib/site-packages')


   Is it me or is that a bug? :)



You can respond by visiting: 

More information about the Python-bugs-list mailing list