I have an object with two attributes file_pathand save_path. If save_pathnot explicitly installed, I want it to have the same meaning as file_path.
I think a way to do this with __setattr__, with something like the following:
class Class():
...
def __setattr__(self, name, value):
if name == 'file_path':
self.file_path = value
self.save_path = value if self.save_path == None else self.save_path
elif name == 'save_path':
self.save_path = value
But it looks like it will give me infinite loops, as it __setattr__is called whenever the attribute is set. So what is the right way to write above and avoid this?
Chuck source
share