I have 3 different config files from which I would want to initialize different class variables for different major functions
Q1. What is the more conventional way of initializing class variables via methods (class methods or methods outside class)
Q2. How to initialize class variables via class methods
config.py
class CONFIG:
x_config = 'x_config.json'
y_config = 'y_config.json'
z_config = 'z_config.json'
>Solution :
Option 1
The most conventional way would be to initialize them in the init method of the class.
Option 2
You can initialize class variables in class methods by using the self keyword. For example:
class MyClass:
def __init__(self):
self.var1 = 1
self.var2 = 2
def class_method(self):
self.var1 = 3
self.var2 = 4