I disapprove of any linter that flags this idiom.
I disapprove of any linter that flags this idiom.
Python doesn't have an “[repeat...]until” loop, which C misspells as “do...while”, which fails to express what is going on.
> so when you want to do a thing at least once, the simplest replacement is starting the loop with "while 1:" and ending the loop with "if ... break".
“while True:” is more idiomatic Python (“while 1:” works since 1 is truthy, but using a literal 1 for “True” is a C-ism, Python has True as a literal for quite some time and idiomatic Python uses it.)
In addition to the GP's self deprecating sibling comment, I started using Python around 2.2, before there were even "True" and "False". So, seeing a 'while 1' loop is perfectly natural to me. But, I'm also perfectly comfortable with Python's "truthiness" in more places than most people are.
As a bonus: consider "while 'false' :" as a perfectly valid start to an unbounded loop.
That sort of thing is ubiquitous in dynamically-typed languages. Even HTML: the state of boolean attributes is determined by the attribute being set, regardless of its value, so <input disabled=false> will give you a nice disabled text box. Mind you, some attributes that you might think would be boolean actually aren’t, for varying reasons good and bad, e.g. autocomplete=on|off, aria-hidden=true|false.
http://python-history.blogspot.com/2013/11/the-history-of-bo...