用于替换函数以完成Ticker的代码



这就是我编码的内容:

def statement(ticker,statement):
if statement =='IS':
temp='income-statement'
elif statement =='BS':
temp='balance-sheet-statement'
else:
temp='cash-flow-statement'

df = tickers.temp(frequency='q') 
return df
tickers=['AAPL','GOOG','TSLA']

我希望函数中的temp替换为df=tickers.temp(frequency='q'(,并在我用股票代码替换tickers时最终给我正确的财务报表。如果有人有类似的合适的代码,请在下面张贴

我真的不确定你想要实现什么。所以我想你有类似的东西

tickers.income-statement()
tickers.balance-sheet-statement()

并且您希望根据该函数中的temp字符串来调用该方法。所以

myfunc = getattr(tickers, temp)

应该从您获得的字符串中为您提供所需的函数。

最新更新