列表使用for循環是這樣的:使用分類排序的對象
for k in time :
def byPrice(stock):
st = stock.get_momentum
return st[k]
s = sorted(obj, key=byPrice)
我想每個股票對象中的勢頭數組中的第k個項目進行排序stock
對象的列表。
class stock:
def __init__(self, name, price):
self.name = name
self.lens = len(price)
def get_momentum(self):
momentum = []
for i in np.arange(lens):
count = close[i]/close[i-60]
momentum.append(count)
return momentum
但是我得到了一個警告,說'method' object is not subscriptable
。並且誤差是在該行st[k]
你沒有調用'get_momentum'。做'st = stock.get_momentum()' –