while expression feature proposal

Chris Angelico rosuav at gmail.com
Fri Oct 26 02:23:12 EDT 2012


On Fri, Oct 26, 2012 at 5:06 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> 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.

while (client.spop("profile_ids") as profile_id) is not None:
    print profile_id

Why is everyone skirting around C-style assignment expressions as
though they're simultaneously anathema and the goal? :)

But seriously, this new syntax would probably enhance Python somewhat,
but you're going to end up with odd edge cases where it's just as
almost-there as current syntax is for what this will solve. Is it
worth doing half the job?

ChrisA



More information about the Python-list mailing list