我正在使用csv writer创建txt文件。
合并列表时添加额外的引号。(分隔它\t)
我在插入之前的最后一个列表是

['20160501-20160531', '719', '1-4', '(1\t1\t12:00-19:00\t1)', '(1\t1\t12:00-19:00\t1)&(2\t1\t01:00-06:00\t2)']

当我写文件的时候
20160501-20160531   719 1-4 "(1 1   12:00-19:00 1)" "(1 1   12:00-19:00 1)&(2   1   01:00-06:00 2)"

为什么还有额外的报价?
一切正常(制表符分隔和全部),除了额外的引号会导致问题
我尝试了quoting=csv.QUOTE_NONE,但只得到escapechar not set的错误
这是我的密码
 for rec in formJson['presentDays']:
        period = '%s-%s'% (scheduleS, scheduleE)
        if not rec['workers']:
            continue
        else:
            workers = ' '.join(str(e) for e in rec['workers'])
            for rr in rec['data']:
                range = '%s-%s' %(rr['loadFrom'],rr['loadTo'])
                #prva vrstica v subdata je condition
                request = rr['subdata'][0]
                request_days = ' '.join(str(x) for x in request['days'])
                request_works = str(request['works'])
                request_time = '%s-%s' %(request['timeFrom'],request['timeTo'])
                request_how = str(request['how'])
                request_row = "(" + request_days + '\t'+ request_works + '\t'+ request_time + '\t'+ request_how + ")"

                #gremo vse nasledne zapise, ki so condition
                itersubdata = iter(rr['subdata'])
                next(itersubdata)
                conditions_rows = []
                for r in itersubdata:
                    condition_days = str(r['days'][0])
                    condition_works = str(r['works'])
                    condition_time = '%s-%s' %(r['timeFrom'],r['timeTo'])
                    condition_how = str(r['how'])
                    condition_row = '(%s\t%s\t%s\t%s)' % (condition_days, condition_works, condition_time, condition_how)
                    conditions_rows.append(condition_row)
                conditions = '&'.join(x for x in conditions_rows)
                record = [period, workers,range,str(request_row), conditions]
                print "record ", record
                output.writerow(record)

有什么建议吗?
谢谢您

最佳答案

似乎需要对包含空格的字符串(本例中为制表符)加引号。

关于python - python csv writer增加额外的引号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37140143/

10-13 03:41