[Python-Dev] Assignment expression and coding style: the while True case
vano at mail.mipt.ru
Thu Jul 5 06:58:42 EDT 2018
On 05.07.2018 9:23, Serhiy Storchaka wrote:
> 05.07.18 01:51, Victor Stinner пише:
>> == Pattern 1, straighforward ==
>> while True:
>> line = input.readline()
>> if not line:
>> IMHO here assingment expression is appropriate here. The code remains
>> straighfoward to read.
>> while (line := input.readline()):
> We already have an idiom for this:
> for line in input:
This is not strictly equivalent: it has internal caching unaffected by
-u and you can't iterate and .read() at the same time.
Though in this specific case (the example is from Lib\base64.py AFAICS),
the change to `for' is fine.
> Python-Dev mailing list
> Python-Dev at python.org
More information about the Python-Dev