Python urlparse.unparse_qsl?

In Python urlparse, you can use urlparse to parse the url and then parse_qsl to parse the request.

I want to remove a query pair (name, value) and then restore the url.

There is a urlunparse method, but not an unparse_qsl method.

What is the correct way to restore a query from a qsl list?

+4
source share
2 answers

The urllib.urlencode function is appropriate.

+2
source
>>> urlparse.parse_qsl('q=stackoverflow') [('q', 'stackoverflow')] >>> urllib.urlencode(urlparse.parse_qsl('q=stackoverflow')) 'q=stackoverflow' 
+2
source

All Articles