Skip to content

Instantly share code, notes, and snippets.

@msikma
Created March 18, 2016 17:31
Show Gist options
  • Save msikma/4a78e21c7844f2bf33ae to your computer and use it in GitHub Desktop.
Save msikma/4a78e21c7844f2bf33ae to your computer and use it in GitHub Desktop.
next_item = Word()
# next_item is either a Word object, which has .is_type(), or it's None
if next_item is None:
# code for situation A
elif next_item.is_type('something'):
# code for situation B
elif next_item.is_type('something_else'):
# code for situation C
else:
# code for situation A
# is there any way I can neatly combine the two situation A?
# I don't want to repeat myself. if I put the 'is None' statement below, it will raise an AttributeError on None.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment