想要模擬一個股票提醒系統,但是出現TypeError: __init__() missing 2 required positional arguments: 'buy' and 'sale'
import tushare
import time
def getrealtimedata(share):
dataNow=tushare.get_realtime_quotes(share.code)
share.name=dataNow.loc[0][0]
share.price=float(dataNow.loc[0][3])
share.high=dataNow.loc[0][4]
share.low=dataNow.loc[0][5]
share.volumn=dataNow.loc[0][8]
share.amount=dataNow.loc[0][9]
share.openToday=dataNow.loc[0][1]
share.pre_close=dataNow.loc[0][2]
share.timee=dataNow.loc[0][30]
share.describe="股票名:"+share.name+"當前價格:"+str(share.price)
return share
#設定股票類
class Share():
def __init__(self,code,buy,sale):
self.name=""
self.price=""
self.high=""
self.low=""
self.volumn=""
self.amount=""
self.openToday=""
self.pre_close=""
self.timee=""
self.describe=""
self.code=""
self.buy=buy
self.sale=sale
def main(code,buy,sale):
share=Share(code)
sss=getrealtimedata(share)
print(sss.describe)
if sss.price<=buy:
print("達到買點,如果有錢趕緊買")
elif sss.price>=sale:
print("達到賣點,如果有錢趕緊賣")
else:
print("別買也別賣,等著")
while 1==1:
main("000591",3.3,3.6)
share("000591")
time.sleep(5)
uj5u.com熱心網友回復:
在main函式中創建Share實體時 只傳遞了一個引數uj5u.com熱心網友回復:
share=Share(code)這里只傳遞了一個code引數,實際上class Share():def __init__(self,code,buy,sale)是需要code,buy,sale三個引數的,要么,后面兩個引數buy, sale附上默認值
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/44934.html
上一篇:python django 求助
下一篇:查找數字Python
