Skip to content

Instantly share code, notes, and snippets.

View bbangert's full-sized avatar
🦊
Numb Numb

Ben Bangert bbangert

🦊
Numb Numb
View GitHub Profile
@shazow
shazow / gist:411284
Created May 23, 2010 21:56
More concise handling of request parameters.
def get_many(d, required=[], optional=[], one_of=[]):
"""
Returns a predictable number of elements out of `d` in a list for auto-expanding.
Keys in `required` will raise KeyError if not found in `d`.
Keys in `optional` will return None if not found in `d`.
Keys in `one_of` will raise KeyError if none exist, otherwise return the first in `d`.
Example usage: