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
{ | |
"metadata": { | |
"name": "" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ |
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
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return "Hello, World!" | |
if __name__ == '__main__': | |
app.run(debug = True) |
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
#!/usr/bin/env python | |
def decorator(func): | |
def wrapper_around_func(): | |
print "Decorator calling func" | |
func() | |
print "Decorator called func" | |
return wrapper_around_func | |
@decorator |
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
#!/usr/bin/env python | |
import inspect | |
from functools import wraps | |
def get_line_number(): | |
# inspect the current frame, go back 2 frames and get the line number. | |
return inspect.currentframe().f_back.f_back.f_lineno |
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
#!/usr/bin/env python | |
def decorator_factory(): | |
def decorator(func): | |
def decorator_wrapper(): | |
print "Decorator calling func" | |
func() | |
print "Decorator called func" | |
return decorator_wrapper | |
return decorator |
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
#!/usr/bin/env python | |
import inspect | |
from functools import wraps | |
def get_line_number(): | |
# inspect the current frame, go back 2 frames and get the line number. | |
return inspect.currentframe().f_back.f_back.f_lineno |
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
#!/usr/bin/env python | |
import inspect | |
from functools import wraps | |
def get_line_number(): | |
# inspect the current frame, go back 2 frames and get the line number. | |
return inspect.currentframe().f_back.f_back.f_lineno |
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
def route(self, rule, **options): | |
def decorator(f): | |
endpoint = options.pop('endpoint', None) | |
self.add_url_rule(rule, endpoint, f, **options) | |
return f | |
return decorator |
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
#!/usr/bin/env python | |
import sys | |
class MyApp(): | |
def __init__(self): | |
self.func_map = {} | |
def register(self, name): | |
def func_wrapper(func): |
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
#!/usr/bin/env python | |
def func1(arg): | |
print "calling func1 with arg " + str(arg) | |
def func2(arg): | |
print "calling func2 with arg " + str(arg) | |
callbacks_dict = { 'func1': func1, 'func2': func2 } | |
callbacks_dict['func1'](1) |
OlderNewer