错误应为StringIO类型,改为获取str

2024-04-26 12:44:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用psycopg2的copy\ from函数将数据批量插入我的postgres数据库。 为了使用这个函数,我尝试使用io.StringIO公司(python 3.x版)。你知道吗

    def __insert_cpe_dic__(self, cpe_dic):
        sio = StringIO
        sio.write('\n'.join(cpe for cpe in cpe_dic))
        sio.seek(0)
        self.cur.copy_from(sio, "cpe_dictionary")

我得到一个错误:“应该是StringIO类型,而不是str…” 写入'sio'变量时。 我找不到任何问题的答案,希望有人能想出办法。你知道吗


Tags: 数据函数fromioself数据库公司postgres