python close file descriptor question

前端 未结 4 1526
日久生厌
日久生厌 2020-11-28 08:20

I think this question is more of a \"coding style\" rather than technical issue.

Said I have a line of code:

buf = open(\'test.txt\',\'r\').readlines         


        
4条回答
  •  心在旅途
    2020-11-28 08:40

    It will be automatically closed, but it depends on implementation exactly when. It's nicer to explicitly use a with-block, but if you are just writing a small script for yourself that you run occasionally it doesn't really matter.

提交回复
热议问题