37,719
社区成员
发帖
与我相关
我的任务
分享
#encoding="utf-8"
import MySQLdb
import types
# vars
# mysql connection
con = None
# connectin's cursor
cursor = None
# fetch from mysql data table
fData = None
# need to handle content
def action():
conn = MySQLdb.connect(host='localhost', user='root', passwd='...', db='testDB', port=8001, charset='gbk')
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor.execute("select * from t_award_info limit 2");
fData = cursor.fetchall();
print getXmlName() + " fetach result : "
print fData
# special output xml file name
def getXmlName():
return "AwardCfg"
# xml file content str
def getXmlStr():
return "test"
# dispose res
def dispose():
print "cursor = ", cursor # cursor = None
cursor.close()
con.close()
#encoding="utf-8"
import MySQLdb
import types
#刚刚这里的变量都删除了
# need to handle content
def action():
global conn #注要这里写上global声明,而注意的是,global这里声明后,不能直接同行赋值,要换行,语法规定?
conn = MySQLdb.connect(host='localhost', user='root', passwd='...', db='testDB', port=8001, charset='gbk')
global cursor
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor.execute("select * from t_award_info limit 2");
global fData
fData = cursor.fetchall();
print getXmlName() + " fetach result : "
print fData
# special output xml file name
def getXmlName():
return "AwardCfg"
# xml file content str
def getXmlStr():
return "test"
# dispose res
def dispose():
print "cursor = ", cursor # 这会这里就不会空了
cursor.close()
print "conn = ", conn
conn.close()
# vars
# mysql connection
con = None
# connectin's cursor
cursor = None
# fetch from mysql data table
fData = None
这少变量
我加了global一样不行