while expression feature proposal
Paul Rubin
no.email at nospam.invalid
Fri Oct 26 02:06:01 EDT 2012
More information about the Python-list mailing list
Fri Oct 26 02:06:01 EDT 2012
- Previous message (by thread): while expression feature proposal
- Next message (by thread): while expression feature proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Dan Loewenherz <dloewenherz at gmail.com> writes: > In this case, profile_id is "None" when the loop breaks. It would be > much more straightforward (and more Pythonic, IMO), to write: > > client = StrictRedis() > while client.spop("profile_ids") as profile_id: > print profile_id That is pretty loose, in my opinion. If the loop is supposed to return a string until breaking on None, the break test should explicitly check for None rather than rely on an implicit bool conversion that will also test as false on an empty string. Code that handles strings should do the right thing with the empty string. What you posted relies on an unstated assumption that the strings that come back are never empty. > it's a net negative from just doing things the canonical way (with the > while / assignment pattern). Yeah, the while/assignment is a bit ugly but it doesn't come up often enough to be a bad problem, imho.
- Previous message (by thread): while expression feature proposal
- Next message (by thread): while expression feature proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list