【发布时间】:2014-11-09 10:02:27
【问题描述】:
这是我用来测试内存分配的代码
import pycurl
import io
url = "http://www.stackoverflow.com"
buf = io.BytesIO()
print(len(buf.getvalue())) #here i am getting 0 as length
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.CONNECTTIMEOUT, 10)
c.setopt(c.TIMEOUT, 10)
c.setopt(c.ENCODING, 'gzip')
c.setopt(c.FOLLOWLOCATION, True)
c.setopt(c.IPRESOLVE, c.IPRESOLVE_V4)
c.setopt(c.USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0')
c.setopt(c.WRITEFUNCTION, buf.write)
c.perform()
c.close()
print(len(buf.getvalue())) #here length of the dowloaded file
print(buf.getvalue())
buf.close()
如何通过 BytesIO 获取分配的缓冲区/内存长度? 我在这里做错了什么? python没有分配固定的缓冲区长度?
【问题讨论】:
-
显示堆栈跟踪。
-
为什么不使用像
requests这样更体面的客户端库? -
@WeaselFox 没有错误我只想知道如何获取分配的内存长度
-
您没有向流中写入任何内容,因此其内容为空。有什么问题?你在说什么内存分配?
-
@interjay python 没有为缓冲区分配固定的内存大小?
标签: python python-3.x