I recently made a class. Let's say that the class is declared as below.
class MyClass(object):
def __init__(self, modifiers):
....
The problem is, I want to create constant instances of the class:
class MyClass(object):
def __init__(self, modifiers):
....
CONSTANT_MEMBER_1 = MyClass(my_modifiers)
CONSTANT_MEMBER_2 = MyClass(my_modifiers)
Unfortunately, Python won't allow me to do so, with error:
E NameError: global name 'MyClass' is not defined
Any solution for this problem?
One alternative would be creating a 'static' method for the class that will return a same object each time it's called (e.g., MyClass.CONSTANT_MEMBER_1()). But I think I would still prefer to access it using MyClass.CONSTANT_MEMBER_1.
Thanks.