How is it better to use the variable storage class?
-
In my global variables storage project, I use class.
Config
type:class Config: # Colors WHITE = Color(255, 255, 255) STAR_COLOR = Color(255, 255, 17) PLANET_COLOR = Color(0, 255, 0) DARK_BLUE = Color(0, 6, 15) TRANSPARENT = Color(0, 0, 0, 0)
BUTTON_GREEN = Color(47, 191, 113) BUTTON_RED = Color(239, 45, 86) # Window WIDTH = 1280 HEIGHT = 720 WINDOW_SIZE = (WIDTH, HEIGHT) FPS = 120 STABLE_FPS = 100 ....
Is that the right walk? Maybe we should move all the variables.
init
and then create the only copy of the classConfig
And then, when imported, use a copy of the class instead of the class itself?
-
I don't know how right this is, but I'd use the module for that purpose.
enum
♪Example:
import enum
class Colors(enum.Enum):
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)print(Colors.BLUE.value)
for i in Colors:
print(i.name)
print(i.value)
There's an article with a pretty good one. https://habr.com/ru/company/timeweb/blog/564826/ ♪