How do I call the file.setter using Python to normalize the path name

1

Code:

class Arquivos:
    @property
    def file(self):
        return self._file

    @file.setter
    def file(self, arquivo):
        if arquivo:
            self._file = os.path.abspath(arquivo)

Call:

Arquivos.file('usp/dados.json')

Error:

File "/home/pc8454/faculdade/python/gerador.py", line 123, in <module>
    Arquivos.file('usp/dados.json')
TypeError: 'property' object is not callable
    
asked by anonymous 21.11.2018 / 17:09

1 answer

3

You are using a property, not defining a static method. So you should create the instance of your class and assign it to the property:

arquivos = Arquivos()
arquivos.file = 'usp/dados.json'

In this way, the function defined in @file.setter will be invoked as desired.

    
21.11.2018 / 17:23