[Python-bugs-list] [ python-Feature Requests-644940 ] Support file path concat with "/"

noreply@sourceforge.net noreply@sourceforge.net
Wed, 27 Nov 2002 12:49:27 -0800


Feature Requests item #644940, was opened at 2002-11-27 20:44
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=644940&group_id=5470

Category: Parser/Compiler
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Mark VanTassel (markvantassel)
Assigned to: Nobody/Anonymous (nobody)
>Summary: Support file path concat with "/" 

Initial Comment:
A very useful feature is to overload the "/" operator for 
strings to support path concatenation - that is, to concat 
the left and right arguments in such a way that there is 
exactly one slash between them, regardless of which 
argument(s) did or didn't include slashes:

dir = "/this/that"
file = "whatever.py"
print dir / file 
#prints "/this/that/whatever.py"

It seems silly, but when you're not 100% in control of 
things (such as when reading paths from config files, 
user input, etc), it's great to be sure that the right thing 
will happen without writing/testing a lot of icky code. 
And even when you are 100% in control, it's nice to not 
have to worry about it so much.

This doesn't seem to conflict with any existing usage or 
syntax, so I don't think it can possibly break any 
existing behaviour (except, of course, those who were 
counting on having an exception thrown!)

I've already coded this as a minor tweak to the Python 
2.2.2 release, and I'd be happy to share the fix with the 
powers that be, if there's general concensus that this is 
a good thing. Feedback is solicited and appreciated 
(this is my first foray into open-source development, so 
be gentle!)

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

>Comment By: Mark VanTassel (markvantassel)
Date: 2002-11-27 20:49

Message:
Logged In: YES 
user_id=658048

P.S. There are a few loose ends for discussion:

1) What to do with empty strings? My current implementation 
doesn't do anything special, so dir/"" ends with a slash, ""/file 
starts with a slash, and ""/"" is a slash. If someone thinks 
different behaviour would be better, I'm open to alternatives.

2) What about back slashes on Windows (my native platform, 
actually)? My version removes trailing slashes and 
backslashes from the 1st arg, and removes leading slashes 
and backslashes from the 2nd ard, and then puts a 
backslash between them... but again I'm open to alternatives.


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

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