On 2022年3月29日 at 09:53, Ethan Furman <[email protected]> wrote: > > In the following bit of code: > > > while s := input.read(MAXBINSIZE): > while len(s) < MAXBINSIZE and ns := input.read(MAXBINSIZE-len(s)): > s += ns > line = binascii.b2a_base64(s) > output.write(line) > > I'm getting this error on the second line: > > cannot use assignment expressions with expression > > Can somebody explain why that isn't working? >
I'm getting a good hint from the exception in 3.11: >>> while len(s) < MAXBINSIZE and ns := input.read(MAXBINSIZE-len(s)): File "<stdin>", line 1 while len(s) < MAXBINSIZE and ns := input.read(MAXBINSIZE-len(s)): ^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: cannot use assignment expressions with expression Looks like it's counting "len(s) < MAXBINSIZE and ns" as the assignment target. Parens around the second half would solve that. ChrisA _______________________________________________ Python-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/E5DAPQX3CODJTU4PTTEDCD6NSMZSTAOB/ Code of Conduct: http://python.org/psf/codeofconduct/