Last active
February 29, 2016 13:29
-
-
Save pixyj/30c1b3eac77d1da1b107 to your computer and use it in GitHub Desktop.
Python decorator to say function's name before it is executed (for OS X)
This file contains 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
""" | |
Usage Example: | |
Case 1 - Debug: Say function name and start pdb before executing add | |
@exec_aloud(debug=True) | |
def add(x, y): | |
return x + y | |
Case 2 - Execute: Say the function name and move on | |
@exec_aloud(debug=False) | |
def add(x, y): | |
return x + y | |
Change the os.system call if you are on another OS. | |
""" | |
def exec_aloud(debug=True): | |
def func_wrapper(fn): | |
def decorator_logic(*args, **kwargs): | |
if debug: | |
message = "Debugging" | |
else: | |
message = "Executing" | |
import os; os.system("say -r 250 {} {}".format(message, fn.__name__)) | |
if debug: | |
import pdb; pdb.set_trace() | |
fn(*args, **kwargs) | |
return decorator_logic | |
return func_wrapper | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment