0

Following that post I have a question about read the file content and save it in instance BytesIO object and afterward closing the file and using BytesIO only. Is it correct usage? If not, does it happen because it is a reference to file bytes? If yes, what are the advantages and does it copy all content from the file to the BytesIO buffer and is thus usable?

Sababoni
  • 4,875
  • 4
  • 20
  • 21
  • 1
    It is correct. The file needs to be in binary mode because `BytesIO` is used. For character files there is `StringIO`. It copies all contents to the `BytesIO` object. Drawbacks are only memory consumption (as mentioned in the answer) and that some functions may need real files as arguments and can't handle Python file-like objects. – Michael Butscher Feb 14 '23 at 09:28

0 Answers0