New submission from Allen Li <[email protected]>:
It would be useful to document that urllib.parse.{Defrag,Split,Parse}Result are
namedtuples, and make that API officially public if it was not otherwise.
These classes are implemented as namedtuples in Python 2 and 3, and I am not
aware of a reason that that would need to change in the future.
In particular, the namedtuple _replace() method is very useful for modifying
parts of a URL, a common use case.
u = urllib.parse.urlsplit(some_url)
u = u._replace(netloc=other_netloc)
urllib.parse.urlunsplit(u)
# Alternatives not depending on namedtuple API
parts = list(u)
parts[1] = other_netloc # Using a magic index
urllib.parse.urlunsplit(u)
u = urllib.parse.SplitResult( # Very ugly
scheme=u.scheme,
netloc=other_netloc,
path=u.path,
query=u.query,
fragment=u.fragment)
----------
assignee: docs@python
components: Documentation
messages: 304637
nosy: Allen Li, docs@python
priority: normal
severity: normal
status: open
title: Document that urllib.parse.{Defrag,Split,Parse}Result are namedtuples
type: enhancement
versions: Python 2.7, Python 3.6
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue31822>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com