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

Asked

Viewed 58 times

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)

Calling for:

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

1 answer

3


You are using a property, not defining a static method. Thus, you must create the instance of your class and make the attribution to the property:

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

Thus, the function defined in @file.setter will be invoked as desired.

  • Thanks, it worked great!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.