Skip to content

Instantly share code, notes, and snippets.

@kwatch
Created September 11, 2015 01:16
Show Gist options
  • Save kwatch/9e59a4efda42fc2b30d0 to your computer and use it in GitHub Desktop.
Save kwatch/9e59a4efda42fc2b30d0 to your computer and use it in GitHub Desktop.
Pythonでは条件によってブロックをスキップするような構文がない
@on('POST', '/foobar')
def do_post(self):
do_something1()
do_something2()
## 残念ながら Python ではブロックをスキップする機能が
## ないのでこれは使えない
with invoke('new_cool_feature_name'):
old_feature1()
old_feature2()
## なので、decoratorをhiger order functionの
## syntax sugar として使うか、
@invoke(:new_cool_feature)
def _():
old_feature1()
old_feature2()
## または for 文を使って「0回または1回の繰り返し」をする
for _ in invoke(:new_cool_feature):
old_feature1()
old_feature2()
#
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment