Python Glossary Русский

all Python 3urllib.parsefunction

urllib.parse.urlunsplit()

URL parsing

Builds a URL back from five parts — a urlsplit() result or any tuple of the same length.

Syntax

urllib.parse.urlunsplit((scheme, netloc, path, query, fragment))

Empty parts are dropped together with '?' and '#', and urlsplit() has already lower-cased the scheme, so a urlsplit→urlunsplit round trip changes the string: 'HTTP://H/p?' becomes 'http://H/p'. To change one part, r._replace(...).geturl() is handier. Values are not escaped — that is the job of quote() and urlencode().

Examples

from urllib.parse import urlsplit, urlunsplit, urlencode
print(urlunsplit(urlsplit('HTTP://H/p?')))  # → http://H/p
query = urlencode({'q': 'a b'})
print(urlunsplit(('https', 'h', '/s', query, '')))  # → https://h/s?q=a+b

See also

Open in the full glossarydocs.python.orgReport an inaccuracy