writing fixed width, space delimited CSV output in Python

后端 未结 3 1732
栀梦
栀梦 2021-01-18 05:43

I would like to write a fixed width, space delimited and minimally quoted CSV file using Python\'s csv writer. An example of the output:

item1           item         


        
3条回答
  •  情深已故
    2021-01-18 06:10

    What does this do for you? I think you really were only missing the csv.QUOTE_NONE constant.

    import csv
    csv.register_dialect('spacedelimitedfixedwidth', delimiter=' ', quoting=csv.QUOTE_NONE)
    with open('crappymainframe.out', 'rb') as f:
        reader = csv.reader(f, 'spacedelimitedfixedwidth')
    

    It's a modification on the unixpwd dialect example at the bottom of the csv module docs.

提交回复
热议问题