Take this code:
>>> import urlparse >>> parts = urlparse.urlparse('http://docs.python.org/library/') >>> parts = parts._replace(path='/3.0'+parts.path)
parts._replace works , but since this is an underlined method, it should be internal and not used. Is there an alternative? I do not want to do:
>>> parts = parts[:2] + ('/3.0'+parts.path,) + parts[3:]
Because this makes it a regular tuple, not a named one, and does:
>>> parts = namedtuple(scheme=parts.scheme, netloc=parts.netloc, etc etc)
looks stupid. :)
Ideas?
python namedtuple
Lennart Regebro
source share