您好我正在尝试将此csv文件导入列表:
00cd3de3903a1dd0c5d10a4da5298088
0164d6463da0f5557c18ee5bf3fa40c6
021471774a61276bca2acc70d2605448
025faee9578c97fbaa0da61d55691758
04dd55ae5d18babc028a8410ca34ce10
0524579c38b45ce3f90865a91d4318a4
05a00c320754934782ec5dec1d5c0476
068ed52dae623cbd44c2198cb0eecda3
07dbd191187a3bfbd1d935cabdd82e24
0c3a1172e21000fe43a5b7894f3e0687
代码如下所示:
with open('\\\\ntsrv1\\Indicators_for_Siem\\IOC1.csv', 'r', ) as temp_file:
readCSV = csv.reader(temp_file, delimiter=',')
for row in readCSV:
new_list.append(row)
输出如下:
[['00cd3de3903a1dd0c5d10a4da5298088'], ['0164d6463da0f5557c18ee5bf3fa40c6'], ['021471774a61276bca2acc70d2605448'], ['025faee9578c97fbaa0da61d55691758'], ['04dd55ae5d18babc028a8410ca34ce10'], ['0524579c38b45ce3f90865a91d4318a4'], ['05a00c320754934782ec5dec1d5c0476'], ['068ed52dae623cbd44c2198cb0eecda3'], ['07dbd191187a3bfbd1d935cabdd82e24'], ['0c3a1172e21000fe43a5b7894f3e0687']]
它看起来不像是列表
我正在寻找一个单一列表的模式,例如:
['value1','value2','value3','value4']
感谢您的帮助
答案 0 :(得分:2)
这不是CSV。只需使用:
with open('input.csv') as temp_file:
new_list = temp_file.read().splitlines()
答案 1 :(得分:0)
行变量是一个列表。
import csv
new_list = []
with open('input.csv', 'r') as temp_file:
readCSV = csv.reader(temp_file, delimiter=',')
for row in readCSV:
new_list.append(row[0])
print(new_list)
将输出:
['00cd3de3903a1dd0c5d10a4da5298088', '0164d6463da0f5557c18ee5bf3fa40c6', '021471774a61276bca2acc70d2605448', '025faee9578c97fbaa0da61d55691758', '04dd55ae5d18babc028a8410ca34ce10', '0524579c38b45ce3f90865a91d4318a4', '05a00c320754934782ec5dec1d5c0476', '068ed52dae623cbd44c2198cb0eecda3', '07dbd191187a3bfbd1d935cabdd82e24', '0c3a1172e21000fe43a5b7894f3e0687']