On Tue, Apr 17, 2018 at 1:54 AM, Steven D'Aprano <st...@pearwood.info> wrote:
> On Mon, Apr 16, 2018 at 06:16:46AM +1000, Chris Angelico wrote:
> [...]
>
>> >> >>> items = [None] * 10
>> >> >>> i = -1
>> >> >>> items[i := i + 1] = input("> ")
>> >> > asdf
>> >> >>> items[i := i + 1] = input("> ")
>> >> > qwer
>> >> >>> items[i := i + 1] = input("> ")
>> >> > zxcv
>> >> >>>
>> >> >>> items
>> >> ['asdf', 'qwer', 'zxcv', None, None, None, None, None, None, None]
>> >
>> >
>> > I don't know why you would write that instead of:
>> >
>> > items = [None]*10
>> > for i in range(3):
>> >     items[i] = input("> ")
>> >
>> >
>> > or even for that matter:
>> >
>> > items = [input("> ") for i in range(3)] + [None]*7
>> >
>> >
>> > but whatever floats your boat. (Python isn't just not Java. It's also
>> > not C *wink*)
>>
>> You and Kirill have both fallen into the trap of taking the example
>> too far. By completely rewriting it, you destroy its value as an
>> example. Write me a better example of a complex target if you like,
>> but the question is about how you feel about complex assignment
>> targets, NOT how you go about creating a particular list in memory.
>> That part is utterly irrelevant.
>
> Chris, I must admit that I'm utterly perplexed at this. Your example is
> as far as from a complex assignment target as you can possibly get. It's
> a simple name!
>
>     i := i + 1
>
> The target is just "i", a name.

Thanks so much for the aggressively-trimmed quote. For once, though,
TOO aggressive. What you're focusing on is the *unrolled* version of a
two-line loop. Look at the actual loop, please, and respond to the
actual question. :|

>> The calls to input were in a while loop's header for a reason.
>> Ignoring them is ignoring the point of assignment expressions.
>
> What while loop? Your example has no while loop.

Not after it got trimmed, no. Here's what I actually said in my original post:

while (read_next_item() -> items[i + 1 -> i]) is not None:
    print("%d/%d..." % (i, len(items)), end="\r")

Now, if THAT is your assignment target, are you still as happy as you
had been, or are you assuming that the target is a simple name?

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to