How can a Python class constant be initialized once, and shared across instances? This is the line of thinking:
class X():
# initialize a constant that will be used by all instances
with open("list_of_valid_words.txt", "r") as f:
VALID_WORDS = [ a.strip() for a in f.readlines() ]
def __init__(self, var):
self.var = var
def valid_object(self):
if self.var in VALID_WORDS: return True
else: return False
a = X("this")
a.valid_object()
NameError: name 'VALID_WORDS' is not defined