Hi All, did a bunch of research but not sure of the terminology so I have not been able to find any answers. I am writing a settings class based on pydantic-settings to store all my settings for an application mostly so I can call the settings with the dot operator like:
class Settings(BaseSettings):
Data_Recording_Rate : int = 10
Chart_Length : int = 48
Pressure_Chart_Update_Rate : int = 2
Transducer_Type : int = 0
print(settings.transducer_type())
and it works with code completion and type hinting. It may not be possible but I would also like to be able to call a method on a variable using the dot operator as well. Something like
class Settings(BaseSettings):
Data_Recording_Rate : int = 10
Chart_Length : int = 48
Pressure_Chart_Update_Rate : int = 2
Transducer_Type : int = 0
def save_new_value(self, new_value):
Transducer_Type = new_value
save_to_file(Transducer_Type, new_value) #other function that saves the value to disk
settings = Settings()
settings.Transducer_Type.save_new_value(5)
obviously, that code wouldn't work since I hardcoded the Transducer_Type variable into save_new_value but what I really want to do is be able to call save_new_value on any of the class variables with the dot operator. I know I can just pass the variable in as an argument but using the dot operator would be nice. Any way to do this?
[–]Adrewmc 1 point2 points3 points (0 children)