From: W. Trevor King Date: Sat, 16 Apr 2011 01:37:07 +0000 (-0400) Subject: Use urllib.urlencode for encoding heavy lifting in entrez.py. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ff97cc7043f941f26158017e0d73153c07ed09b6;p=blog.git Use urllib.urlencode for encoding heavy lifting in entrez.py. --- diff --git a/posts/entrez/entrez.py b/posts/entrez/entrez.py index 30a6566..60ae214 100755 --- a/posts/entrez/entrez.py +++ b/posts/entrez/entrez.py @@ -86,20 +86,8 @@ del _handler, _formatter ## XML and list utility functions def urlencode(param_dict): - params = "" - for key,value in param_dict.items(): - if value == None: - continue # ignore unused parameter - #if type(value)== : # convert True/False to 'y'/ - # if value == True: - # params += "%s=y&" % (key,) - # #else: - # # params += "%s=n&" % (key,) - if value != None: - params += "%s=%s&" % (key, str(value)) - if len(params) > 1: - params = params[:-1] # remove trailing & - return params + return urllib.urlencode( + [(k,v) for k,v in param_dict.iteritems() if v is not None]) def unique(seq, keepstr=True): """