Skip to content
Advertisement

Python list comprehension, invalid syntax [closed]

In some part of my program i have this code:

from os import walk

def get_missing_parts(count, directory_name):
  filenames = next(walk(directory_name, (None, None, []))[2]
  parts = [i for i in range(1, count + 1) if not f"seg-{i}-v1-a1.ts" in filenames]
  return parts

Traceback

  File "/home/td/tmp/g/g.py", line 5
    parts = [i for i in range(1, count + 1) if not f"seg-{i}-v1-a1.ts" in filenames]
    ^
SyntaxError: invalid syntax

Advertisement

Answer

You did not close the next() function call. Try using an IDE, it will highlight brackets and parenthesis for you to show where you might have forgotten to close one.

filenames = next(walk(directory_name, (None, None, []))[2]

Should be

filenames = next(walk(directory_name), (None, None, []))[2]

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement