运行后出现错误。Traceback most recent call last File Dwampwwwinvest批量获取财务数据py line 9 in module stocks = row1 for row in csvreaderf1 File Dwampwwwinvest批量获取财务数据py line 9 in listcomp stocks = row1 for r
这个错误通常是由于CSV文件中的一行没有足够的元素导致的。在这种情况下,使用try-except块可以捕获错误并跳过这些行。例如:
import csv
with open('stocks.csv', 'r') as f: try: stocks = [row[1] for row in csv.reader(f)][1:] except IndexError: print("Error: CSV file has row with insufficient elements.") stocks = [] # or another fallback value
continue with processing the stocks list...
原文地址: https://www.cveoy.top/t/topic/bdW0 著作权归作者所有。请勿转载和采集!