I have a class MyLib with variable x. I do not use this variable outside the class but I do set it from another class outside the package. I would like to know what is the preferred way to set value to the variable x below. Should I set it directly as shown in the code snippet below or Should I create @property and @x.setter functions to set it.
class MyLib:
def __init__(self, *args, **kwargs)
self._x = None
def func_to_process_x():
# do something
class UseLib:
self._x = 'ABC'
Note: This question is not about wether to use properties over getter and setters. Rather I would like to know if it is advisable to use properties /getter/setters at all if we can directly use the variables, since nothing is private in Python.
Further is it recommended to use properties even when I am not doing anything in the @x.setter
function apart from simply assigning the value to the variable. Basically wondering if the overhead of properties is worth in the name of encapsulation (even though it is not encapsulation in pure sense since nothing is private. Please correct me if I am wrong here)