Oct-15-2021, 03:50 PM
(This post was last modified: Oct-15-2021, 03:50 PM by deanhystad.)
I think having the __init__ method check a class variable should work great for this.
If this is not applicable to your problem, why not? Can you explain please.
class Thing: parameters = None # Stuff you want to read once and use many times @classmethod def init_parameters(cls): '''Load parameters from a file. All instances will share these parameters''' # Open file an read parameters cls.parameters = whatever() def __init__(self): if self.parameters is None: self.init_parameters() # Initialize these class variables from a file. Happens once. #Can use the parameters nowSounds like all instances will share these parameters, so it makes sense to use a class variable to reference them.
If this is not applicable to your problem, why not? Can you explain please.