1

I have CSV file with data like this =

'01,02,VM001,02,21,0ffadb' 
'01,02,VM001,02,21,0aadbcd'
'01,02,VM001,02,21,012adbc'

I want make into string like this :

"['01,02,VM001,02,21,0aadbcd'], ['01,02,VM001,02,21,0aadbcd'],['01,02,VM001,02,21,012adbc']"

My code like this:

datalist = " ".join(map(str,data)).replace ("'","") 

data is list that get from read CSv file. But I get like this :

"[01,02,VM001,02,21,0aadbcd], 
[01,02,VM001,02,21,0aadbcd],
[01,02,VM001,02,21,012adbc]"

Thanks for your help

1 Answer 1

1

If the data in your CSV file is row based

with open(filename, 'r') as input_file:
    datalist = []
    for line in input_file:
        datalist.append(line.strip().split(','))

will read in each line at a time, and strip whitespace and new line characters, and split it based on your comma delimiter.

Sign up to request clarification or add additional context in comments.

1 Comment

If you're getting that error, you must be altering line before trying to strip it as it will be a string as returned by the file iterator. Are you trying to split before strip ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.