On Thu, 8 Jun 2023 at 08:19, Jason Friedman via Python-list <python-list@python.org> wrote: > > This gives the expected results: > > with open(data_file, newline="") as reader: > csvreader = csv.DictReader(reader) > for row in csvreader: > #print(row) > match row[RULE_TYPE]: > case "RANGE": > print("range") > case "MANDATORY": > print("mandatory") > case _: > print("nothing to do") > > This: > > RANGE = "RANGE" > MANDATORY = "MANDATORY" > with open(data_file, newline="") as reader: > csvreader = csv.DictReader(reader) > for row in csvreader: > #print(row) > match row[RULE_TYPE]: > case RANGE: > print("range") > case MANDATORY: > print("mandatory") > case _: > print("nothing to do") > > Gives (and I don't understand why): > > SyntaxError: name capture 'RANGE' makes remaining patterns unreachable
It's being as clear as it can. When you say "case RANGE:", that is not a literal, that is a name capture. Check the docs and examples for case statements for more details. ChrisA -- https://mail.python.org/mailman/listinfo/python-list