fakeMake
fakeMake

Reputation: 778

TypeError in_io.BytesIO with Python3

I'm trying to read a file in io but it returns an error. It's giving me a TypeError which I'm not able to solve. This is the code I'm using:

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]

It returns this error

TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO

Upvotes: 0

Views: 442

Answers (1)

Ruslan
Ruslan

Reputation: 189

just don't use open, but use csvdata=csv.reader(buf, delimiter=",")

Upvotes: 1

Related Questions