创建lis有问题

2024-10-03 00:26:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我做了一个股票筛选程序,它给出了符合我标准的股票的技术参数,最后,我希望它能打印出符合我标准的股票的简明列表。我尝试使用append函数,但它只打印一个股票,相反,我希望它打印每个股票的股票代码,例如“mmm”,。。。你知道吗

电流输出如下所示。 嗯 尾随市盈率:17.61 股本回报率:54.34% 收入:323.5亿 季度收入增长:-5.00%


def scrape(stock_list, interested, technicals):
    for each_stock in stock_list:
        technicals = scrape_yahoo(each_stock)
        condition_1 = float(technicals.get('Return on Equity',0).replace('%','').replace('N/A','-100')) > 25
        condition_2 = float(technicals.get('Trailing P/E',0).replace('N/A','')) > 15
        condition_3 = float(technicals.get('Price/Book (mrq)',0)) <15
        if (condition_1 and condition_2)==True:
            print(each_stock)
            SuggestedStocks = []
            SuggestedStocks.append(each_stock)  
            for ind in interested: 

                print(ind + ": "+ technicals[ind])         
            print("------")
            time.sleep(1)                                                    # Use delay to avoid getting flagged as bot
    #return technicals
    print(SuggestedStocks)


def main():

    stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD']
    interested = ['Trailing P/E', 'Return on Equity', 'Revenue', 'Quarterly Revenue Growth']
    technicals = {}

    tech = scrape(stock_list, interested, technicals)
    print(tech)
main()

它只打印符合我要求的最后一支股票的股票代码标准:ADBE。你知道吗


Tags: 标准getstockfloatconditionreplacelist股票