[path-PEP] Path inherits from basestring again

Tim Golden tim.golden at viacom-outdoor.co.uk
Tue Jul 26 11:17:02 EDT 2005


[Peter Hansen]
| 
| Ron Adam wrote:
| >>>> Tony Meyer wrote:
| >>>>> Do people really like using __div__ to mean join?  
| 
| > I think the '+' is used as a join for both strings and lists, so it 
| > would probably be the better choice as far as consistency with the 
| > language is concerned.
| 
| The issue with that is that as long as we are subclassing 
| strings, the + 
| is already defined for a useful operation and the subclass probably 
| shouldn't be changing the way that works.

Well, I actually had some correspondence with Jason on this
very subject a year or so ago:

<email>

[Me]
| Not sure if it's a bug or a feature, but __add__ does a + on the two
| strings/paths while the __div__ does a join. The principal difference from
| my point of view is that if I add two absolute paths:  [...]

[Jason]
| Well... from my point of view, it's a feature... :)
| The purpose of + is (for example) to add extensions to the end of filenames:
|     p = path('C:\\blorpl\\flarg.txt')
|     z = p + '.zip'
| Without it, this would be pretty awkward.
| (path.__add__ is overloaded only to make this operation return a path
| object.  Otherwise it would return a plain string.)
| The other purpose of + is so that a path behaves just like a string for all
| string operations.  This means you can safely pass a path object to any
| function that expects a string.

</email>

Obviously, I don't know how much weight Jason's original ideas have on
the prepped-for-syslib module, but it does support what other people
have been saying: that the Path should behave like a string where a
string is expected.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list