Python Glossary Русский

Python 3.2+urllib.parseterm

urllib.parse.DefragResultBytes

parse results

The result of urldefrag() for bytes: the same (url, fragment) tuple, but the fields are byte strings.

Syntax

DefragResultBytes(url, fragment)

The result type follows the argument: bytes in, bytes out, so r.fragment == 'x' is False. decode() turns it into a DefragResult, and DefragResult.encode() goes the other way. Mixing str and bytes in one call is a TypeError.

Examples

from urllib.parse import urldefrag
r = urldefrag(b'http://h/p#x')
print(r.fragment, r.fragment == 'x')  # → b'x' False
print(r.decode())  # → DefragResult(url='http://h/p', fragment='x')

See also

Open in the full glossarydocs.python.orgReport an inaccuracy