BadPython.com

Suggestion for "Using custom getters and setters"

1. getX does not require any parameters, 2. @property and @x.setter decorators should be used or 3. you should just access MyClass().x without writting a method
            
class MyClass():
    def __init__(self, x):
        self._x = x
    
    @x.setter
    def x(self, x):
        # print("setting a")
        self._x = x
    
    @property
    def x(self):
        # print("getting a")
        return self._x

# Can be called without ()
# a = MyClass(3)
# a.x = '3' # the setter function a.x is called with the x argument '3'  
# a.x # the getter function a.x is called