[Python-ideas] Is there a good reason to use * for multiplication?

MRAB python at mrabarnett.plus.com
Mon Oct 15 22:14:17 CEST 2012


On 2012-10-15 20:37, Jasper St. Pierre wrote:
> On Mon, Oct 15, 2012 at 3:12 PM, Mike Graham <mikegraham at gmail.com> wrote:
>>> def __\u2295__(self, other):
>>>
>>> Now *that's* pretty!
>>>
>>>     <mike
>>
>>
>> IMO it's essential that we add source code escapes. Imagine the
>> one-liners this will allow!
>>
>>     def f(xs):\n\ttry:\n\t\treturn x.pop()\n\texcept ValueError\n\t\treturn None
>>
>> Can we get this fix applied in Python 2.2 and up?
>
> Yeah, this is how Java works, and it's one of the best features of the
> language, because any valid program can be expressed using ASCII only.
>
> Of course, it means that there are going to be some edge cases. Like, now:
>
>      print "\n"
>
> will be an invalid program, since the newline escape will be
> translated before the source is tokenized. But who does that? It's
> just a small price to pay for the big wins of having any program
> expressed in simple ASCII.
>
Simple:

     print "\\n"




More information about the Python-ideas mailing list