[Python-ideas] PEP 428 - object-oriented filesystem paths

Andrew McNabb amcnabb at mcnabbs.org
Sat Oct 6 01:54:57 CEST 2012


On Sat, Oct 06, 2012 at 08:41:05AM +1000, Steven D'Aprano wrote:
> On 06/10/12 05:53, Andrew McNabb wrote:
> 
> >Path concatenation is obviously not a form of division, so it makes
> >little sense to use the division operator for this purpose.
> 
> But / is not just a division operator. It is also used for:
> 
> * alternatives: "tea and/or coffee, breakfast/lunch/dinner"
> * italic markup: "some apps use /slashes/ for italics"
> * instead of line breaks when quoting poetry
> * abbreviations such as n/a b/w c/o and even w/ (not applicable,
>   between, care of, with)
> * date separator

This is the difference between C++ style operators, where the only thing
that matters is what the operator symbol looks like, and Python style
operators, where an operator symbol is just syntactic sugar.  In Python,
the "/" is synonymous with `operator.div` and is defined in terms of the
`__div__` special method.  This distinction is why I hate operator
overloading in C++ but like it in Python.

--
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55  8012 AB4D 6098 8826 6868



More information about the Python-ideas mailing list