【问题标题】:Code to replace a function to complete a Ticker替换函数以完成 Ticker 的代码
【发布时间】:2020-07-08 11:40:31
【问题描述】:

这是我编码的:

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') 并最终在我用股票代码替换股票代码时给我正确的财务报表。如果有人有类似的合适代码,请在下面发布

【问题讨论】:

    标签: function ticker


    【解决方案1】:

    我不太确定你想要达到什么目标。 所以我假设你有类似的东西

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

    ... 并且您想根据该函数中的临时字符串调用该方法。 所以

    myfunc = getattr(tickers, temp)
    

    应该从你实现的字符串中给你想要的功能。

    【讨论】:

      猜你喜欢
      • 2015-08-18
      • 2012-07-08
      • 2021-08-15
      • 1970-01-01
      • 2015-04-27
      • 2011-04-06
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多