0

我从将 csv 转换为 xml 的脚本中得到这个

语法错误 无效语法

print(text, file=self.file, end=self.args.linebreak)

该点在第一个“=”下。我不确定这是为什么。有人可以指出正确的方向。

谢谢阿朗佐

class Writer:
def __init__(self, ofile, args):
    self.file = ofile
    self.args = args
    self.newline_subst = field_subst_factory(args.newline_elem)
    if args.header:
        self.fieldname = self.__fieldname_header
    elif args.flat_fields:
        self.fieldname = self.__fieldname_flat
    else:
        self.fieldname = self.__fieldname_indexed
def write_file(self, data):
    if self.args.declaration:
        declaration = ('<?xml version="1.0" encoding="{0}"?>'.
                       format(args.oencoding))
        self.write(declaration)
    self.write("<{0}>".format(self.args.root_elem))
    for record in data:
        self.write_record(record)
    self.write("<\{0}>".format(self.args.root_elem))
def write_record(self, record):
    self.write("{0}<{1}>".
               format(self.args.indent, self.args.record_elem))
    for index, field in enumerate(record):
        self.write_field(field, index)
    self.write("{0}<\{1}>".
               format(self.args.indent, self.args.record_elem))
def write_field(self, field, index):
    self.write("{0}{0}<{1}>{2}</{1}>".
               format(self.args.indent, self.fieldname(index),
                      self.newline_subst(field)))
def write(self, text):
    **print(text, file=self.file, end=self.args.linebreak)** This the line that's causing issues
def __fieldname_header(self, index):
    return self.args.header[index]
def __fieldname_flat(self, index):
    return self.args.field_elem
def __fieldname_indexed(self, index):
    return self.args.field_elem + str(index)
4

1 回答 1

4

如果您使用的是 python 2.x,那么您需要将以下行放在代码的顶部

from __future__ import print_function
于 2013-06-28T19:14:59.040 回答