Open a file (of type BytesIO) with the function

I have the following pieces of code: this part generates the CSV in memory: def to_csv(events: list) -> io.BytesIO(): if not events: return None bio = io.BytesIO() iow = io.TextIOWrapper(bio) writer = csv.DictWriter(iow, fieldnames=events[0].keys()) writer.writeheader() writer.writerows(events) iow.flush() bio.seek(0) return bio this part sends this file to the FTP server: def send_data(self, bytes: io.BytesIO) -> str:… Read More Open a file (of type BytesIO) with the function