Skip to content

Instantly share code, notes, and snippets.

@mnuck
Created June 15, 2012 16:35
Show Gist options
  • Save mnuck/2937474 to your computer and use it in GitHub Desktop.
Save mnuck/2937474 to your computer and use it in GitHub Desktop.
Why if/else will eventually bite you
# option 3 (ternary)
for perm in ['modify', 'view', 'execute']:
fn = assign_perm if request.POST[perm] == "public" else remove_perm
fn(perm, anon, rs)
# option 3.1 (switch/case-in-a-dict)
fn_selector = {"public" : assign_perm,
"private" : remove_perm }
for perm in ['modify', 'view', 'execute']:
fn_selector[request.POST[perm]](perm, anon, rs)
# option 3.1.5 (switch/case-in-a-dict)
fn_selector = {"public" : assign_perm,
"private" : remove_perm,
"acl_controlled" : ACLify_perm}
for perm in ['modify', 'view', 'execute']:
fn_selector[request.POST[perm]](perm, anon, rs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment