Skip to content

Instantly share code, notes, and snippets.

@n1ywb
Created October 21, 2012 01:48
Show Gist options
  • Save n1ywb/3925430 to your computer and use it in GitHub Desktop.
Save n1ywb/3925430 to your computer and use it in GitHub Desktop.
Example use case for functools.partial
def render(self, request):
# Encapsulate the function call we wish to make into a partial object.
# Now if we change the function name or arguments we only change them
# in ONE place, instead of the two places this function is called from.
f = functools.partial(self.dlstatus.stn_to_json, self.id)
try:
request.setHeader("content-type", "application/json")
if request.args.has_key('callback'):
request.setHeader("content-type", "application/javascript")
return request.args['callback'][0] + '(' +
f() + ')'
return f()
except Exception, e:
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment