-2
我需要解析一個文件,它具有以下內容: result(x1 y1 x2 y2... xn yn)
這是我寫的python中的一段代碼。我是python的新手。for循環與Python中的多個變量
xs =[] ys=[]
def __init__(self,xs,ys):
self.xs = xs
self.ys = ys
def toString(self):
return "result " + " (" + " ".join([x.toString()+ " " + y.toString() for x,y in zip(self.xs, self.ys)]) + ") "
我在運行時出現AttributeError: 'str' object has no attribute 'toString'
錯誤。請建議如何解決這個問題。
只要確保:所有這一切都是在課堂上正確的?因爲否則'自我'沒有意義 – alonisser
是的。第一行寫在調用之前。解析結果(x1 x2 ... xn)我有下面的代碼,它工作正常。 def toString(self): return「result」+「」.join([x.toString()for x in self.xs])+「)」我需要用這種形式寫。 – user1727270