Created
September 16, 2011 13:58
-
-
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
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
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