assignment in control structure syntax (was Re: Curious assignment behaviour)
huaiyu at gauss.almadan.ibm.com
Thu Oct 11 00:00:13 CEST 2001
I have an alternative syntax that could satisfy both safety and simplicity.
It did not receive much notice the last time here, though. The full
explanation is at http://www.geocities.com/huaiyu_zhu/python/ififif.txt
On Wed, 10 Oct 2001 09:47:11 +0200, Just van Rossum <just at letterror.com> wrote:
>Paul Rubin wrote:
>> Anyway, I can live with "while x:=get_next()" instead of x=get_next.
>> But I feel seriously cramped in Python when I have to say
>> while 1:
>> if not x: break
>> so I hope something is done about the issue.
while x = get_next(); x:
>I think this is the wrong example, as it can easily be written as a
>for loop. Iterators in 2.2 will make that even more natural. Now if
>you meant this:
> m = someRegex.match(...)
> if m:
> if m := someRegex.match(...):
>you may have a point...
if m = someRegex.match(...); m:
There are several other uses for this syntax. For example,
if val = dict1[key1]; val:
elif val = dict2[key2]; val:
elif mylist += otherlist; len(mylist) > 4:
These are arguably easier to understand than current Python syntax.
See the link above for more examples.
Is there much interest to turn this into a PEP?
More information about the Python-list