[Patches] [ python-Patches-1748960 ] Extra optional argument to os.path.expandvars

SourceForge.net noreply at sourceforge.net
Fri Jul 6 17:54:38 CEST 2007


Patches item #1748960, was opened at 2007-07-06 12:06
Message generated for change (Comment added) made by gjb1002
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1748960&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Geoffrey Bache (gjb1002)
Assigned to: Nobody/Anonymous (nobody)
Summary: Extra optional argument to os.path.expandvars

Initial Comment:
I've several times wanted to expand a string in the way that os.path.expandvars does, but without modifying the actual environment.

If for example I have 

inputString = "$ROOT/${SUBDIR}/some/path"

and I want to find expanded versions of this, I have to do something like

os.environ["ROOT"] = "/users/geoff"
os.environ["SUBDIR"] = "subdir"
fullPath = os.path.expandvars(inputString)

The problem is that my program is multithreaded and I don't want to globally change os.environ. All I want is the information "fullPath". I'd like to be able to create a local "env" dictionary and pass it to os.path.expandvars as an optional second argument.

I attach a patch for posixpath.py and ntpath.py, though this is untested and is intended to show what I mean in practice.


----------------------------------------------------------------------

>Comment By: Geoffrey Bache (gjb1002)
Date: 2007-07-06 17:54

Message:
Logged In: YES 
user_id=769182
Originator: YES

I've now attached a better patch, which is tested at least on UNIX for
now. Decided it was better if the optional argument was a function to
replace os.getenv, as then it can be called only on demand and there isn't
a need to set up information unnecessarily, or call any code more than
once.

File Added: patch

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1748960&group_id=5470


More information about the Patches mailing list