vendredi 7 mars 2014

How to get a python function to return object instead of string


Vote count:

0




I have a function:



def getXMLpayload(server):
try:
result = urllib2.urlopen('http://%s' % server, None, 15)
except urllib2.URLError:
return 'unknown'
except:
raise Exception('Unexpected response from server')
return result


I want it to return a urllib2 object so that in another function I can call the above function and then use its output like so:



xmlPayload = result.read()
tree = ET.ElementTree(ET.fromstring(xmlPayload))
root = tree.getroot()


I think it is currently returning a string instead, how would I get it to return the "object"?



asked 8 secs ago






Aucun commentaire:

Enregistrer un commentaire