Skip to content

Instantly share code, notes, and snippets.

@tschellenbach
Created September 16, 2011 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tschellenbach/1222181 to your computer and use it in GitHub Desktop.
Save tschellenbach/1222181 to your computer and use it in GitHub Desktop.
Very super simple url param replace for when u cant use a querydict
import re
def replace(url, key, value):
p = re.compile('%s=[^=&]*' % key, re.VERBOSE)
return p.sub('%s=%s' % (key, value), url)
url = 'http://www.google.com/?a=b&c=d&d=f'
print replace(url, 'a', 'test')
print replace(url, 'c', 'test')
print replace(url, 'd', 'test')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment