Skip to content

Instantly share code, notes, and snippets.

@apg
Created July 14, 2009 18:55
Show Gist options
  • Save apg/147111 to your computer and use it in GitHub Desktop.
Save apg/147111 to your computer and use it in GitHub Desktop.
# instead of:
match = someregex.match(line)
if match:
print match.groups()
else:
print 'boo'
# why not make use of the 'as' keyword and do something like:
if someregex.match(line) as match:
print match.groups()
else:
print 'boo'
# this is a horrible elif example, but similarly, it's just as nice.
if someregex.match(line) as match:
print match.groups()
elif someregex2.match(line) as match:
print match.groups()
else:
print 'boo'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment