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'] -- https://mail.python.org/mailman/listinfo/python-list