PEP20 sound amazing, but then when this only way end up being way too verbose/ugly, you are kind of stuck with it. Compare:
#python
import re
m = re.search('(a.+)(d.+)', 'abcdef')
if m:
print(f"{m.group(1)},{m.group(2)}")
#perl
if('abcdef' =~ /(a.+)(d.+)/){
print "$1,$2";
}
Re:New string formatting in Python
by JoshTriplett on Sunday January 03, 2016 @08:33PM
(#10833545)
I don't know why Python re match objects don't support indexing; a __getitem__ method would allow m[1] and m[2] instead (or m['name'] for named groups).
That aside, though, I don't consider brevity alone the most critical criteria for a programming language; that way lies APL. Expressiveness, yes, but not at the expense of clarity.
There are a couple of warts for sure, but Python is remarkably wart free. Compare it to something wart ridden like PHP or JavaScript.
keyword is "preferably".
Also "Simple is better than complex", "practicality beats purity" and "Readability counts".
The zen is not the bible, you don't get to cherrypick the stuff you want to make your case.
Plus, they are just guide lines, in the end, you have a debate in the python dev mailing list with reasonable people making their case.
Re:New string formatting in Python
by eugenekolo2 on Sunday January 03, 2016 @08:36PM
(#10833557)
Preferably one. Unfortunately they put in `format`, and can't remove it now. I think moving towards f-strings is a lot better and should be embraced.
Re:New string formatting in Python
by mixmastamyk on Sunday January 03, 2016 @08:53PM
(#10833602)
Format is still needed for non-literals and user objects, this is just an extension of it.
Re:New string formatting in Python
by mixmastamyk on Sunday January 03, 2016 @11:22PM
(#10833971)
"Practicality beats purity."
"There should be one-- and preferably only one --obvious way to do it."
There are a lot of warts on that snake, but I still really like using Python.