[Python-ideas] issue15824

Ben Toews mastahyeti at gmail.com
Thu Aug 30 21:03:49 CEST 2012

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'

What do other people think?

-Ben Toews

More information about the Python-ideas mailing list