data = ['wrq~,p~,sdvvzrug,zzz edlgx frp dx\n',
'wrq~,p~,sdv,vzrug,zzz jrrjoh frp dx\n']
for item in data:
text1 = item.split(",")[0]
text2 = item.split(",")[1]
text3 = item.split(",")[2].strip()
print(text1)
print(text2)
print(text3)
I'm using python to write and read files.The data was stored in comma-separated text file. Then I'm using readlines() converted to list of strings. Then use split(",") seperate by comma. However i need the output like this
text1=wrq~
text2=p~,sdvvzrug
text3=zzz edlgx frp dx
second string of the list will be the same
text1=wrq~
text2=p~,sdv,vzrug
text3=zzz edlgx frp dx
Basic each string has three parts. either part maybe will contain some comma,so how to split string by comma and not remove the comma inside each part?
CSVformat with appropriate quoting (done automatically by thecsvmodule)