cpython
cpython copied to clipboard
NameError in class definition using list comprehension with if statement
This code works
class A:
data = ' '
remains = [c for c in data]
This code gives us NameError: name 'data' is not defined
class A:
data = ' '
remains = [c for c in data if c in data]
Is there any valid reason why this happens (running Python 3.9)?