假设我有这个代码:
>>> import urlparse
>>> url = "http://google.com"
>>> s = urlparse.urlsplit(url)
>>> print s
SplitResult(scheme='http', netloc='google.com', path='', query='', fragment='')
>>> print 'scheme ',s.scheme
scheme http
>>> print 'netloc ',s.netloc
netloc google.com
如您所见,我可以手动迭代这些项目,但如何自动执行此操作?我想做这样的事情:
# This doesn't work:
for k,v in s.items():
print '%s : %s'%(k,v)