0

I'm using python2.7. In my script i receive lines from server in next format:

product,"Tom,Jerry\\n",r,0
product,Another Title,r,1

So i need read this string line by line. And then read 4 values to list. But i can't simple do split(","), because we can have , character in title.

Arti
  • 7,356
  • 12
  • 57
  • 122

1 Answers1

2

The csv module can read lines from a list.

>>> import csv
>>> S = """product,"Tom,Jerry\\n",r,0
... product,Another,r,1"""
>>> for row in csv.reader(S.splitlines()):
...     print row
... 
['product', 'Tom,Jerry\\n', 'r', '0']
['product', 'Another', 'r', '1']
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
  • thanks, this answer also help: http://stackoverflow.com/questions/3305926/python-csv-string-to-array – Arti Dec 15 '15 at 20:48