创建列表时遇到问题
Trouble with creating list
我制作了一个股票筛选器,可以提供符合我标准的股票的技术指标,最后,我希望它能打印一份符合我标准的简明股票清单。我尝试使用追加功能,但它只打印一只股票,相反,我希望它打印每只打印的股票的代码,例如 'mmm',...
当前输出如下所示。
嗯
尾随 P/E:17.61
Return 股权:54.34%
收入:32.35B
季度收入增长:-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()
它只打印符合我的 criteria:ADBE 的最后一只股票的代码。
这是因为你在每次循环中都重置了建议股票SuggestedStocks = []
你应该在循环外初始化它。
我制作了一个股票筛选器,可以提供符合我标准的股票的技术指标,最后,我希望它能打印一份符合我标准的简明股票清单。我尝试使用追加功能,但它只打印一只股票,相反,我希望它打印每只打印的股票的代码,例如 'mmm',...
当前输出如下所示。 嗯 尾随 P/E:17.61 Return 股权:54.34% 收入:32.35B 季度收入增长:-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()
它只打印符合我的 criteria:ADBE 的最后一只股票的代码。
这是因为你在每次循环中都重置了建议股票SuggestedStocks = []
你应该在循环外初始化它。