Python handles globals badly.

Antoon Pardon antoon.pardon at rece.vub.ac.be
Fri Sep 11 12:19:45 CEST 2015


Op 10-09-15 om 18:48 schreef Chris Angelico:
> I'm not sure what the point would be of having an expression that
> doesn't return a value. The point of assignment-as-an-expression is
> that you can do other things with the result:
>
> while ((ch=getchar()) != EOF)
>
> In Python, we have a couple of cases where that's done with the 'as' keyword:
>
> with open(fn) as in_file:
>
> except KeyError as e:
>
> and there've been proposals now and then to have the same thing added
> to if and while, which actually isn't hard:
>
> while getchar() as ch:

I just don't get why people want to introduce special cases in python.
Why allow such a construct only in while and if? Why not just allow
it generally as an assignment expression?

Why not allow:

  while (f(x) as fx) > 5:
    proces(fx)

or

  if check(nextvalue() as new):
    treat(new)

One of the things I don't like about python is the limitation of the
slice syntax. I have been in situations where the natural thing to
do was write a method that takes a slice as a parameter and
have it called like: for key, value in Tree.items(lowkey:highkey).

But that doesn't work because slice notation is only allowed in
a subscription context.

It is kind of frustrating when you see something in the language
you think useful, to then notice the language doesn't allow you
to use in the context you need/want it.

At this moment I feel that introducing the "as v" possibily only
in while and if statements would mainly enlargen my frustration.

-- 
Antoon Pardon



More information about the Python-list mailing list