Skip to content

Instantly share code, notes, and snippets.

@TheWaWaR
Last active August 29, 2015 14:04
Show Gist options
  • Save TheWaWaR/76ce7cfca7379cdabf68 to your computer and use it in GitHub Desktop.
Save TheWaWaR/76ce7cfca7379cdabf68 to your computer and use it in GitHub Desktop.
Build url with params
import urllib
def build_url(url, params):
query_string = '&'.join(['='.join([k, urllib.quote(v)]) for k, v in params.iteritems()])
return '{}?{}'.format(url, query_string)
params = {
'abc':'some#def',
'integer': '234123'
}
url = 'http://www.example.com/query'
print build_url(url, params)
## http://www.example.com/query?integer=234123&abc=some%23def
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment