Skip to content

Instantly share code, notes, and snippets.

{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "Hello, World!"
if __name__ == '__main__':
app.run(debug = True)
#!/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
#!/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
#!/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
#!/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
#!/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
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
#!/usr/bin/env python
import sys
class MyApp():
def __init__(self):
self.func_map = {}
def register(self, name):
def func_wrapper(func):
#!/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)