bytearray引用与值类型?

2024-10-02 12:32:02 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python中,当bytearray传递给函数时,它是通过引用传递还是通过值传递?

在python3.7中,我试图模拟HTTPResponse对象进行测试。当我从内部复制代码时http.client.HTTPResponse对象我得到的结果与标准库得到的结果不同。

我的代码:

#I call the mock buffer like this
intBytesBuffered = self.HTTPResponseMock.readinto(tempBuffer)

HTTPResponseMock

^{pr2}$

相关函数来自http.client.HTTPResponse找到了here行436-500

标准库中最重要的摘录如下,read calls readinto:

b = bytearray(amt)
n = self.readinto(b)
return memoryview(b)[:n].tobytes()

标准库在调用缓冲区时做的事情和我差不多,但是当它运行时,摘录中的bytearry b会返回其中的数据。当我调用read时,tempBuffer返回空值?


Tags: the对象函数代码selfclienthttpread

热门问题