Prevent TextIOWrapper from closing on GC in a Py2/Py3 compatible way

前端 未结 4 681
面向向阳花
面向向阳花 2021-01-12 02:34

What I need to accomplish:

Given a binary file, decode it in a couple different ways providing a TextIOBase API. Ideally these subseque

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-12 03:16

    A simple solution would be to return the variable from the function and store it in script scope, so that it does not get garbage collected until the script ends or the reference to it changes. But there may be other elegant solutions out there.

提交回复
热议问题