Python paradigms

Tim Peters tim_one at email.msn.com
Sun Apr 9 06:39:21 CEST 2000


[Nick Maclaren]
> Well, starting to use Python, there are two Algol 68 constructions
> that I sorely miss.  Here is an example of them in C:
>
>     if ((x = non_trivial_expression) != NULL) {
>         do_something_using_x;
>     } elif ((x = another_expression) != NULL) {
>         do_something_else_using_x;
>     } ...
>
> and:
>
>     x = (a != NULL ? a[i]->weeble : 0) + (b != NULL ? b[i]->wombat : 0)
>
> It is pretty obvious why Python doesn't have the former, but I am
> a bit puzzled as to the reason for the lack of the latter.  Or
> maybe I just haven't found it yet :-)

It's just a FIR (Frequently Ignored Request <wink>).  3-argument getattr and
dict.get() and builtin max() and min() cover many common cases, and nobody
has screamed loud enough to overcome Guido's reluctance to add more syntax
for others, which *can* be done easily with obvious if/else sequences.  Note
that the C

    a() ? b() : c()

is equivalent (including evaluating only one of b and c) to the Python
atrocity

   (a() and [b()] or [c()])[0]

But you'll be shot if you ever use the latter, so forget I said that.

no-relief-in-sight-ly y'rs  - tim







More information about the Python-list mailing list