Reputation: 9501
I am using a csv file that I am iterating over each line and make each column a different title.
for i in csvreader:
1 = i[0]
2 = i[1]
etc.
however the 2 column has spaces after the text in the column 'text '. I need to removed the spaces after the text. I need 'text', with no spaces at the end.
I know I could just remove it from the CSV in excel, but I need to do this with Python I am not wanting to open CSV file and work with it.
I have tried to replace
and strip
, but I can't get this to work. Any suggestions?
Upvotes: 1
Views: 256
Reputation: 142156
Just use:
with open('some.csv') as fin:
csvin = csv.reader(fin):
for row in csvin:
cols = [col.strip() for col in row]
pass # whatever
Upvotes: 0