基本 Python StringIO —— 为什么 GetValue() 什么也不返回?
我遇到了基本的 python 问题。在下面的示例中,没有返回错误,但使用 pprint 显示所有变量的内容显示 contents is = '' ——为什么会出现这种情况?
import sys, os, re, StringIO, pprint, time
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
import pycurl
url = "http://google.com/";
strio = StringIO.StringIO()
curlobj = pycurl.Curl()
curlobj.setopt(pycurl.URL, url)
curlobj.perform()
curlobj.close()
contents = strio.getvalue()
strio.close()
有什么想法吗?谢谢
I'm having basic python issues.. In the following example no errors are returned but displaying the contents of all variables using pprint shows that contents is = '' -- why would this possibly be the case?
import sys, os, re, StringIO, pprint, time
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
import pycurl
url = "http://google.com/";
strio = StringIO.StringIO()
curlobj = pycurl.Curl()
curlobj.setopt(pycurl.URL, url)
curlobj.perform()
curlobj.close()
contents = strio.getvalue()
strio.close()
Any ideas? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看涉及
StringIO
的行。这些语句都没有从
curlobj
中提取内容。所以strio
是空的。编辑(感谢@Alexander Cameron 和@agf):
也许你的意思是
Look at the lines that involve
StringIO
.None of these statements draw content from
curlobj
. Sostrio
is empty.Edit (thanks to @Alexander Cameron and @agf):
Perhaps you meant
您永远不会对
strio
变量执行任何操作。您必须将其传递给某个函数才能将任何内容写入其中。You never do anything with your
strio
variable. You have to pass it in to some function in order for anything to get written to it.