I’m using urllib2 to read in a page. I need to do a quick regex on the source and pull out a few variables but urllib2 presents as a file object rather than a string.
I’m new to python so I’m struggling to see how I use a file object to do this. Is there a quick way to convert this into a string?
You can use Python in interactive mode to search for solutions.
if
fis your object, you can enterdir(f)to see all methods and attributes. There’s one calledread. Enterhelp(f.read)and it tells you thatf.read()is the way to retrieve a string from an file object.