I have a csv-file (containing +1000 lines and \t
is used as delimiter) that I want to load into Python as a list. Here are the first few lines of the file:
"col1" "col2" "col3" "col4" "col5" "col6"
1 "01-01-2017 00:00:00" "02-02-2017 00:00:00" "str1" "str3" "str4 åå here comes a few newline characters
"
2 "01-01-2017 00:00:00" "02-02-2017 00:00:00" "str2" "str3" "str5 åasg here comes more newlines
"
As you can see, the strings tend to contain many newline-characters. Is there a way to strip the strings for all newline characters and then make a list containing all rows?
My attempt: Based on this thread here is my attempt:
import csv
with open('test.dat') as csvDataFile:
csvReader = csv.reader(csvDataFile, delimiter="\t")
for i in csvReader:
print(list(map(str.strip,i)))
However, this doesn't strip anything.