[Python-Dev] suggestion: except in list comprehension
Josiah Carlson
jcarlson at uci.edu
Wed Apr 26 21:29:31 CEST 2006
"tomer filiba" <tomerfiliba at gmail.com> wrote:
> first, i posted it two days ago, so it's funny it got posted only now...
> the moderators are sleeping on the job :)
I don't believe python-dev has moderators...or at least my posts have
never been delayed like that.
> > Note that of the continue cases you offer, all of them are merely simple
> > if condition
>
> yes, i said that explicitly, did you *read* my mail?
After reading your syntax I read over the samples you provided.
Generally speaking, I get far too much email to read the ful content of
every "I think Python should have feature/syntax/whatever X", especially
when those posts begin with "my friend had this idea". Let your friend
post if if (s)he thinks it important, or at least post the idea on
python-list first. Python-dev shouldn't be the starting point of these
syntax discussions, it should be near the ending point.
> but i also said it's not always possible. you *can't* always tell prior to
> doing something.
Of course you can't. But you know what? In all the times I've used
list comprehensions over the last few years, I've never wanted, nor
needed, the functionality you describe. Would it be convenient? Sure.
But there are many other additions that I would find more convenient,
and would likely find more use, which have been rejected.
> anyway, i guess my friend may have better show-cases, as he's the one who
> found the need for it. i just thought i should bring this up here. if you
> think better show cases would convince you, i can ask him.
I think that the syntax is unnecessary, and no amount of use-cases that
your friend can supply will likely convince me otherwise (unless your
friend happens to be a core Python developer - in which case he would
have posted him/herself).
> > If you couldn't guess; -1, you can get equivalent behavior without
> > complicating the generator expression/list comprension syntax.
>
> so how come list comprehensions aren't just a "complication to the syntax"?
> you can always do them the old way,
>
> x = []
> for ....:
> x.append(...)
List comprehensions were designed with this one particular simple
use-case in mind. Look through the standard library at the number of
times that simple for loops with appends are used. Go ahead. Take your
time. Now go ahead and count the cases where the only difference is a
try/except clause. Compare that count. Note how the simple case is
likely close to 10 times as common as the try/except case? THAT's why
the simple version was included, and that's why I don't believe that
except is necessary in list comprehensions.
> don't worry, i'm not going to argue it past this.
Good, I think it's a nonstarter.
- Josiah
More information about the Python-Dev
mailing list