Skip to content

Instantly share code, notes, and snippets.

@fereria
Created January 30, 2015 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fereria/2a18de75c201b49db2e9 to your computer and use it in GitHub Desktop.
Save fereria/2a18de75c201b49db2e9 to your computer and use it in GitHub Desktop.
deco args test
## -*- coding: utf-8 -*-
"""
decoratorに引数を持たせる
"""
import sqlite3
import charcode
def dbConnect(dbfile):
def _dbConnect(func):
def __dbConnect(*args,**kw):
con = sqlite3.connect(dbfile)
csr = con.cursor()
result = func(csr)
con.close()
return result
return __dbConnect
return _dbConnect
@dbConnect("./db/jpTest.db")
def test(csr=None):
csr.execute('select name,price from test;')
for name,price in csr.fetchall():
print name.encode('utf-8')
print price
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment