Re: [Python-ideas] issue15824

Hello, We have been discussing the value of having namedtuple as the return type for urlparse.urlparse and urlparse.urlsplit. See that thread here: http://bugs.python.org/issue15824 . I jumped the gun and submitted a patch without seeing if anyone else thought different behavior was desirable. My argument is that it would be a major usability improvement if the return type supported item assignment. Currently, something like the following is necessary in order to parse, make changes, and unparse: import urlparse url = list(urlparse.urlparse('http://www.example.com/foo/bar?hehe=haha')) url[1] = 'python.com' new_url = urllib.urlunparse(url) I think this is really clunky. I don't see any reason why we should be using a type that doesn't support item assignment and needs to be casted to a another type in order to make changes. I think an interface like this is more useful: import urlparse url = urlparse.urlparse('http://www.example.com/foo/bar?hehe=haha') url.netloc = 'www.python.com' urlparse.urlunparse(url) What do other people think? -- -Ben Toews

Le 30/08/2012 21:51, Serhiy Storchaka a écrit :
Note that namedtuples *are* immutables, but they have a _replace method that returns a new namedtuple. This method could also be extended to handle the properties that are computed dynamically (username, password, host, port). Regards, -- Simon Sapin

Le 30/08/2012 21:51, Serhiy Storchaka a écrit :
Note that namedtuples *are* immutables, but they have a _replace method that returns a new namedtuple. This method could also be extended to handle the properties that are computed dynamically (username, password, host, port). Regards, -- Simon Sapin
participants (3)
-
Ben Toews
-
Serhiy Storchaka
-
Simon Sapin