[Python-ideas] if-statement in for-loop

Paul Moore p.f.moore at gmail.com
Wed Oct 5 13:13:52 EDT 2016


On 5 October 2016 at 17:26, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Compared to those, locally modifying the token stream to inject ":
> INDENT" pairs when the if and for keywords are encountered between an
> opening "for" keyword and a closing ":" keyword would be a relatively
> straightforward change that only impacted folks that decided they
> preferred that particular flavour of Abbreviated Python to the regular
> version.

It's also worth noting that the obvious response "but I don't want to
have to run a preprocessor against my code" is another indication that
this isn't solving a significant enough problem to warrant a language
change. Again, this isn't a hard and fast rule, but it is a useful
rule of thumb - how much effort are you willing to go to to get this
feature without it being built in? That's one of the reasons "it
should be made into a module on PyPI" is a useful counter to proposals
for new stdlib functions. It's also worth looking at the cases where
things get added despite not going via that route - sometimes "being
built in" is an important benefit of itself. But typically that's
because people are encouraged to use built in facilities, so guiding
beginners (or not-so-beginners) into good practice is important. In
this case, it's far from clear that the feature is actually good
practice.

Paul


More information about the Python-ideas mailing list