If I have a python class that looks like this:
class MyClass(object):
def __init__(self, path):
self.path = path
I know I can change the path attribute in an instance of the object like this:
my_example = MyClass("home/data")
my_example.path = "home/other_data"
However, I have seen some code where people use functions to set attributes like this:
class MyClass(object):
def __init__(self, path):
self.path = path
def setPath(self, path):
self.path = path
If I want the user of an instance of the class to be able to change an attribute, it is best practice to have a function for this like in the second example, or to just let them change it manually like the first example?