Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python urlparse.unparse_qsl?

In Python's urlparse, you can use urlparse to parse the URL, and then parse_qsl to parse the query.

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

There is a urlunparse method, but no unparse_qsl method.

What is the correct way to reconstruct the query from the qsl list?

like image 896
Joseph Turian Avatar asked Oct 08 '22 00:10

Joseph Turian


2 Answers

The function urllib.urlencode is appropriate.

like image 119
Joseph Turian Avatar answered Oct 13 '22 11:10

Joseph Turian


>>> urlparse.parse_qsl('q=stackoverflow')
[('q', 'stackoverflow')]

>>> urllib.urlencode(urlparse.parse_qsl('q=stackoverflow'))
'q=stackoverflow'
like image 28
Senthil Kumaran Avatar answered Oct 13 '22 12:10

Senthil Kumaran