2018-05-23 17:54 GMT+03:00 Mike Miller <python-ideas@mgmiller.net>:
On 2018-05-22 14:32, Kirill Balunov wrote:
# in global scope everything works ok since locals is globals
>>> while len( this( val = dummy() ) ) >= 0:
... print(val)
[0, 1]
[0, 1, 2]
[0, 1, 2, 3]
Interesting! Although the example with a len() and mutable default arguments obscured the utility, I thought. Also, why limit it to one assignment?
I just want some dummy example which can not be trivially handled with `for name in iter(func, value)`. But the latter is also only partly true. You can make something like:The only restriction is that you can not pass arguments to a `func`, but this, to some extent, can also be handled with lambda. I limit it to _one assignment_ firstly to make it simple, and secondly to get rid of some edge cases.class P:__slots__ = ('func')def __init__(self, func):self.func = funcdef __eq__(self, other):return not self.func(other)for val in iter(dummy, P(lambda x: len(x) < 5)):print(val)[0, 1][0, 1, 2][0, 1, 2, 3]Liked Terry's suggestions for name. The name that jumped into my brain as I read was a reuse of the locals() or globals() callable with key words, that would change their behavior to what you suggest.I like `this` because it is easy to follow in my opinion: " While this name assigned to an expression is greater than zero do... " But of course I'm open to any other spelling. I'm just wondering, if someone like this form as an alternative for assignment expression (`:=`).With kind regards,-gdg
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/