def set_url_query_parameter(url, param_name, param_value):
 if (not isinstance(param_name, basestring)):
  raise Exception(('URL query parameter name must be a string, received %s' % param_name))
 (scheme, netloc, path, query_string, fragment) = urlparse.urlsplit(url)
 query_params = urlparse.parse_qs(query_string)
 query_params[param_name] = [param_value]
 new_query_string = urllib.urlencode(query_params, doseq=True)
 return urlparse.urlunsplit((scheme, netloc, path, new_query_string, fragment))

def set_url_query_parameter ( url , param_name , param_value ) : if ( not isinstance ( param_name , basestring ) ) : raise Exception ( ( 'URL query parameter name must be a string, received %s' % param_name ) ) ( scheme , netloc , path , query_string , fragment ) = urlparse . urlsplit ( url ) query_params = urlparse . parse_qs ( query_string ) query_params [ param_name ] = [ param_value ] new_query_string = urllib . urlencode ( query_params , doseq = True ) return urlparse . urlunsplit ( ( scheme , netloc , path , new_query_string , fragment ) )
set or replace a query parameter .