How do I process this?
alex23
wuwei23 at gmail.com
Tue Mar 4 21:28:45 EST 2014
On 4/03/2014 2:03 PM, Igor Korot wrote:
> Hi, ALL,
> I have a csv file which depending on how it was produced gives 2
> different strings as shown in the example below (test1 and test2).
> I am only interested in the first field in test1 and obviously in the
> whole string of test2.
> >>> test1 = "a,,,,"
> >>> test2 = "a"
Try using the csv module:
>>> from StringIO import StringIO
>>> csvfile = StringIO()
>>> csvfile.write('a,,,,\n')
>>> csvfile.write('a\n')
>>> csvfile.seek(0)
>>>
>>> import csv
>>> reader = csv.reader(csvfile)
>>> [x[0] for x in reader]
['a', 'a']
More information about the Python-list
mailing list