Created
January 30, 2015 15:43
-
-
Save fereria/2a18de75c201b49db2e9 to your computer and use it in GitHub Desktop.
deco args test
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
## -*- 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