TypeError in_io.BytesIO with Python3

问题描述 投票:0回答:1

我正在尝试在io中读取文件,但它返回错误。它给了我我无法解决的TypeError。这是我正在使用的代码:

str_summary = pd.read_sql("SELECT * FROM '" + str(overall_summary) + "'", conn)
s = io.StringIO()
csv.writer(s).writerows(str_summary)
s.seek(0)
buf = io.BytesIO()
buf.write(s.getvalue().encode())
buf.seek(0)
buf.name = f'data1.csv'
with open(buf) as red:
    csvdata=csv.reader(red,delimiter=",")
    tdata=[]
    for row in csvdata:
        rowdata = []
        BLANK=row[0]
        A1 =row[1]
        A2=row[2]
        B3=row[3]
        B4=row[4]
        B5=row[5]
        C6=row[6]
        C7=row[7]
        C8=row[8]

它返回此错误

TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO
python stringio
1个回答
0
投票

只是不使用open,而是使用csvdata=csv.reader(buf, delimiter=",")

热门问题
推荐问题
最新问题