parse comma separated csv file with quotes in python

前端 未结 1 1815
礼貌的吻别
礼貌的吻别 2020-12-11 02:49

Below i have a string which represents a single row pulled from a csv file. Each column is separated by a comma and the value is wrapped in \"\". What is the simplest way to

相关标签:
1条回答
  • 2020-12-11 03:47

    Python has a module for that:

    http://docs.python.org/library/csv.html

    import csv, sys
    filename = 'some.csv'
    with open(filename, 'rb') as f:
        reader = csv.reader(f)
        try:
            for row in reader:
                print row
        except csv.Error, e:
            sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
    
    0 讨论(0)
提交回复
热议问题