【发布时间】:2014-04-15 21:16:22
【问题描述】:
好的,还有一个 TypeError。这是我的代码:
class musssein:
def notwendig(self, name):
self.name = name
all = [] # fuer jede Eigenschaft eine extra Liste
day = []
time = []
prize = []
what = []
kategorie = []
with open(name) as f:
for line in f:
data = line.replace('\n','') #Umbruchzeichen ersetzen
if data != ' ': # immer nur bis zur neuen Zeile bzw. bis zum ' ' lesen
all.append(data) # in liste einfuegen
else:
kategorie.append(all.pop())
what.append(all.pop())
prize.append(all.pop())
time.append(all.pop())
day.append(all.pop())
def anzeige():
musssein.notwendig('schreiben.txt')
print table.Table(
table.Column('Datum', day),
table.Column('Kategorie', kategorie),
table.Column('Was?', what),
table.Column('Preis', prize, align=table.ALIGN.LEFT))
描述是德语,但它向我解释了您可能已经知道的内容。
当我现在运行 anzeige() 时,终端只显示我:
File "test.py", line 42, in anzeige
musssein.notwendig('schreiben.txt')
TypeError: unbound method notwendig() must be called with musssein instance as first argument (got str instance instead)
我尝试了很多可能性并阅读了很多其他主题,但我没有找到正确的解释它的主题。
【问题讨论】:
标签: python class python-2.7 typeerror