What to do after Python?

Erik Max Francis max at alcyone.com
Mon Feb 19 11:52:28 EST 2001


Kenneth Loafman wrote:

> AArgh!  Been doing Python too long!  You can't assign in an if
> statement
> in Python, so the awkward construct represented the worst of both.  In
> retrospect, I'd probably write something like:
> 
>     if (s[0])
>        s[strlen(s)-1] = 0

There's nothing wrong with using assignment in an if conditional,
provided that's what you actually meant.  Good compilers will warn, and
you can typically suppress the warning by adding another layer of
parentheses:

    if ((length = strlen(s)))
        ...

Making assignment illegal in expressions is to prevent _accidental_
cases like this.  If the language allows them and it's intentional,
there's nothing wrong.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Life is painting a picture, not doing a sum.
\__/ Oliver Wendell Holmes, Jr.
    Esperanto reference / http://mirror/alcyone/max/lang/esperanto/
 An Esperanto reference for English speakers.



More information about the Python-list mailing list