-2

so this works on my pc running v3.8.5 but on my pc with python v3.7.3 it throws a syntax error and points to ' := ' as the error.

ls = ['hi', 'hello', 'bye', 'goodbye', 'adios']

for i in (t := tqdm(ls, ncols=103, leave=False, ascii=' #')):
    t.set_description(i)
    sleep(1)

i know i can just do

t = tqdm(ls, ncols=103, leave=False, ascii=' #')

for i in t:
    t.set_description(i)
    sleep(1)

but would rather not... Any ideas what the issue is? both machines are running same version of tqdm.

drebrb
  • 70
  • 1
  • 6
  • 1
    Can you clarify what you are asking? The issue is precisely that ``:=`` is a syntax error in Python 3.7 – it was added in Python 3.8. There is no further issue than what Python is telling you itself. – MisterMiyagi Mar 09 '21 at 21:13
  • 1
    Does this answer your question? [“:=” syntax and assignment expressions: what and why?](https://stackoverflow.com/questions/50297704/syntax-and-assignment-expressions-what-and-why) – MisterMiyagi Mar 09 '21 at 21:16

1 Answers1

2

The walrus operator is a new addition in Python 3.8. See PEP 572:

https://www.python.org/dev/peps/pep-0572/

Dan
  • 91
  • 2