I have the variable assignment in order to return the assigned value and compare that to an empty string, directly in the while loop.
Here is how I\'m doing it in PH
No, sorry. It's a FAQ, explained well here:
In Pydocs, and Fredrik Lundh's blog.
The reason for not allowing assignment in Python expressions is a common, hard-to-find bug in those other languages.
Many alternatives have been proposed. Most are hacks that save some typing but use arbitrary or cryptic syntax or keywords, and fail the simple criterion for language change proposals: it should intuitively suggest the proper meaning to a human reader who has not yet been introduced to the construct.
An interesting phenomenon is that most experienced Python programmers recognize the
while Trueidiom and don’t seem to be missing the assignment in expression construct much; it’s only newcomers who express a strong desire to add this to the language.There’s an alternative way of spelling this that seems attractive:
line = f.readline() while line: ... # do something with line... line = f.readline()