Why the class attr cannot be used in this way?
class A:
a = 1
d = [1, 2, 3, 4]
e = [i for i in d if i == a]
print(e)
and the error message is like this below:
Traceback (most recent call last):
File "/home/gavinc/code/eigen_clients/gavinc/a002.py", line 3, in <module>
class A:
File "/home/gavinc/code/eigen_clients/gavinc/a002.py", line 7, in A
e = [i for i in d if i == a]
File "/home/gavinc/code/eigen_clients/gavinc/a002.py", line 7, in <listcomp>
e = [i for i in d if i == a]
NameError: name 'a' is not defined
there will be no error if I write this out side of a class, something like the following code:
a1 = 1
d1 = [1, 2, 3, 4]
e1 = [i for i in d1 if i == a1]
print(e1)