csv.writerow()引发AttributeError

时间:2019-02-11 17:20:35

标签: python python-3.x csv

正如标题所述,使用AttributeError时得到csv.writerow()

我正在尝试使用csv.writerow()将值添加到csv文件中。

代码:

import csv

class File:
    def __init__(self, f):
        self.f = f

    def __add__(self, other):
        with open(self.f, mode='a') as f:
            writer = csv.writer(f, delimiter=',', quotechar='"')
            f.writerow(str(other))
            return self.__str__()

o = File('file.csv')
s = o + 2

我希望代码为csv文件添加一个新值,并用逗号将其与其他值分开。 错误报告的整个行如下所示: AttributeError: '_io.TextIOWrapper' object has no attribute 'writerow'

0 个答案:

没有答案
相关问题