Jun-18-2019, 02:36 AM
HI!
I'm trying to create a class with getters and setters in python mode because there are too many attributes to pass as argument in __init__ method.
So, here what i did:
So I have two questions:
1- How can I fix this error?
2- What is the proper way to set the default value for those strings?
I'm trying to create a class with getters and setters in python mode because there are too many attributes to pass as argument in __init__ method.
So, here what i did:
class Tale: def __init__(self): self._title = "" self._author = "" self._category = "" self._date = None #it will be datetime object self._score = 0 self._tale = "" self._numChars = 0 @title.setter def title(self, title): self._title = title @author.setter def author(self, author): self._author = authorx @category.setter def category(self, category): self._category = category @date.setter def date(self,date): self._date = date @score.setter def score(self,score): self._score = score @tale.setter def tale(self,tale): self._tale = tale @numChars.setter def numChars(self,numChars): self._numChars = numChars @property def title(self): return self._title @property def author(self): return self._author @property def category(self): return self._category @property def date(self): return self._date @property def score(self): return self._score @property def tale(self): return self._tale @property def numChars(self): return self._numCharsAnd that's the error message:
Quote:python test/main.py
Traceback (most recent call last):
File "test/main.py", line 4, in <module>
import tale
File "test/tale.py", line 1, in <module>
class Tale:
File "test/tale.py", line 11, in Tale
@title.setter
NameError: name 'title' is not defined
So I have two questions:
1- How can I fix this error?
2- What is the proper way to set the default value for those strings?