使用“with open”时,函数read()的源在哪里?
我需要找出在哪里调用了返回值。
我只找到了一些空的函数,像这样:
def read(self, __size: int = ...) -> bytes | None: ...
或者这样:
@abstractmethod
def read(self, n: int = -1) -> AnyStr:
pass
1 个回答
-1
with语句其实就是一个上下文管理器,它负责处理文件描述符的创建和释放。
with open(file) as fin
这和下面的代码是一样的
fin = open(file)
…
fin.close()
你想要的具体信息可以在open的文档里找到