Created
September 27, 2011 22:33
-
-
Save eloff/1246455 to your computer and use it in GitHub Desktop.
Add query params to url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urlparse import urlparse, urlunparse | |
from urllib import urlencode | |
def add_query_args(uri, **params): | |
parts = list(urlparse(uri)) | |
qs = urlencode(params) | |
if parts[4]: | |
parts[4] += '&' + qs | |
else: | |
parts[4] = qs | |
return urlunparse(parts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment