[Python-Dev] Assignment expression and coding style: the while True case
Antoine Pitrou
solipsis at pitrou.net
Thu Jul 5 07:06:12 EDT 2018
More information about the Python-Dev mailing list
Thu Jul 5 07:06:12 EDT 2018
- Previous message (by thread): [Python-Dev] Assignment expression and coding style: the while True case
- Next message (by thread): [Python-Dev] Assignment expression and coding style: the while True case
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, 5 Jul 2018 13:58:42 +0300 Ivan Pozdeev via Python-Dev <python-dev at python.org> wrote: > 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: > >> break > >> ... > >> > >> 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. You are only talking about Python 2 here. Regards Antoine.
- Previous message (by thread): [Python-Dev] Assignment expression and coding style: the while True case
- Next message (by thread): [Python-Dev] Assignment expression and coding style: the while True case
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list