Basic Python StringIO -- Why is GetValue() Returning Nothing?
I'm开发者_如何学JAVA 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
Look at the lines that involve StringIO
.
strio = StringIO.StringIO()
contents = strio.getvalue()
strio.close()
None of these statements draw content from curlobj
. So strio
is empty.
Edit (thanks to @Alexander Cameron and @agf):
Perhaps you meant
curlobj.setopt(pycurl.WRITEFUNCTION, strio.write)
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.
精彩评论