I'd like to pass a URI to a constructor and get back an object on which I can call obj.type, obj.host, obj.port, etc. The "Request" object of the urllib2 module is close to what I need, but not quite it.
+5
A:
Maybe something like the urlparse
module?
The
urlparse
module is renamed tourllib.parse
in Python 3.0.
From the doc:
>>> from urlparse import urlparse
>>> o = urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
>>> o # doctest: +NORMALIZE_WHITESPACE
ParseResult(scheme='http', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html',
params='', query='', fragment='')
>>> o.scheme
'http'
>>> o.port
80
>>> o.geturl()
'http://www.cwi.nl:80/%7Eguido/Python.html'
gimel
2010-02-08 05:56:56
Thanks, this module is precisely what I need.
Jeff Hammerbacher
2010-02-08 23:02:01