0

Hi i am trying to import this csv file to a list:

00cd3de3903a1dd0c5d10a4da5298088
0164d6463da0f5557c18ee5bf3fa40c6
021471774a61276bca2acc70d2605448
025faee9578c97fbaa0da61d55691758
04dd55ae5d18babc028a8410ca34ce10
0524579c38b45ce3f90865a91d4318a4
05a00c320754934782ec5dec1d5c0476
068ed52dae623cbd44c2198cb0eecda3
07dbd191187a3bfbd1d935cabdd82e24
0c3a1172e21000fe43a5b7894f3e0687

the code looks like this:

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)

the output looks like this:

[['00cd3de3903a1dd0c5d10a4da5298088'], ['0164d6463da0f5557c18ee5bf3fa40c6'],      ['021471774a61276bca2acc70d2605448'], ['025faee9578c97fbaa0da61d55691758'],   ['04dd55ae5d18babc028a8410ca34ce10'], ['0524579c38b45ce3f90865a91d4318a4'], ['05a00c320754934782ec5dec1d5c0476'], ['068ed52dae623cbd44c2198cb0eecda3'], ['07dbd191187a3bfbd1d935cabdd82e24'], ['0c3a1172e21000fe43a5b7894f3e0687']]

not it looks like a list of lists

and i am looking for a pattern of singe list for example:

['value1','value2','value3','value4']             

thank you for your assistance

1
  • change to new_list.append(row[0]) Commented May 15, 2017 at 13:08

2 Answers 2

2

That is not a CSV. Just use:

with open('input.csv') as temp_file:
    new_list = temp_file.read().splitlines()
Sign up to request clarification or add additional context in comments.

1 Comment

Your solution is more elegant. I posted code that indicated a specific point in the original code. Upvoting :)
0

The row variable is a list.

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)

Will output:

['00cd3de3903a1dd0c5d10a4da5298088', '0164d6463da0f5557c18ee5bf3fa40c6', '021471774a61276bca2acc70d2605448', '025faee9578c97fbaa0da61d55691758', '04dd55ae5d18babc028a8410ca34ce10', '0524579c38b45ce3f90865a91d4318a4', '05a00c320754934782ec5dec1d5c0476', '068ed52dae623cbd44c2198cb0eecda3', '07dbd191187a3bfbd1d935cabdd82e24', '0c3a1172e21000fe43a5b7894f3e0687']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.