Python 3.2+urllib.parseterm
urllib.parse.DefragResult
parse results
The result of urldefrag() for a str: a named tuple of the URL without its fragment (url) and the fragment itself (fragment).
Syntax
DefragResult(url, fragment)
Before 3.2 urldefrag() returned a plain tuple, so old code unpacks it into two variables — that still works. With no fragment, fragment is an empty string, not None. geturl() glues the address back together with the hash sign. It is a tuple: unpacking and indexing work, but fields cannot be assigned — _replace() returns a new object and geturl() turns it back into a string.
Examples
from urllib.parse import urldefrag
r = urldefrag('http://h/p#sec')
print(r.url, r.fragment) # → http://h/p sec
print(r.geturl()) # → http://h/p#sec
print(type(r).__name__) # → DefragResult
See also
Open in the full glossarydocs.python.orgReport an inaccuracy