Created
September 11, 2015 01:16
-
-
Save kwatch/9e59a4efda42fc2b30d0 to your computer and use it in GitHub Desktop.
Pythonでは条件によってブロックをスキップするような構文がない
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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