這裏是我Transaction
類:TypeError:'str'對象不可調用// class?
class Transaction(object):
def __init__(self, company, price, date):
self.company = company
self.price = price
self.date = date
def company(self):
return self.company
def price(self):
return self.price
def date(self):
self.date = datetime.strptime(self.date, "%y-%m-%d")
return self.date
,當我試圖運行date
功能:
tr = Transaction('AAPL', 600, '2013-10-25')
print tr.date()
,我發現了以下錯誤:
Traceback (most recent call last):
File "/home/me/Documents/folder/file.py", line 597, in <module>
print tr.date()
TypeError: 'str' object is not callable
如何我能解決這個問題嗎?
你不能有一個與方法同名的實例變量,顯然 –