Last active
August 9, 2016 12:05
-
-
Save tokibito/c9fe174957c93dfe42bdb0c0b5debd20 to your computer and use it in GitHub Desktop.
その時間がすぎたら実行できないというデコレータを作ってみてください
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
import datetime | |
def decorator(limit_time): | |
def factory(func): | |
def wrapped(*args, **kwargs): | |
now = datetime.datetime.now() | |
if limit_time < now: | |
raise Exception( | |
"{} を過ぎているので実行できません。now={}".format( | |
limit_time, now) | |
) | |
return func(*args, **kwargs) | |
wrapped.__name__ = func.__name__ | |
wrapped.__doc__ = func.__doc__ | |
return wrapped | |
return factory | |
@decorator(datetime.datetime(2016, 8, 9, 10, 0)) | |
def main(): | |
print("test") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment