I am using Python 2.7 and I am trying to define an enum class
from test_module import BannerType
class LoginBannerType:
Login_Banner_Flag = 1 << 4
VALUE_TO_NAME = dict(
(k, v) for k, v in BannerType.VALUE_TO_NAME.items() if (k & Login_Banner_Flag))
Here Login_Banner_Flag
refers to the class-level attribute I just defined but when I try import this enum class, I got this error:
(k, v) for k, v in BannerType.VALUE_TO_NAME.items() if (k & Login_Banner_Flag))
NameError: global name 'Login_Banner_Flag' is not defined
I tried to change that line to the following but it does not work either:
VALUE_TO_NAME = dict(
(k, v) for k, v in BannerType.VALUE_TO_NAME.items() if (k & LoginBannerType.Login_Banner_Flag))
So it is a comprehension and I am supposed to get reference to outer variables right? What is wrong with my code and how to fix this?