1. 关于数据库连接
首先,别忘了import cx_Oracle
db = cx_Oracle.connect(user, password, dbaddress)
cursor = db.cursor()
rs = cursor.execute(statement)
接下来,如果是从数据库读取数据:
result = rs.fetchall()
db.close()
return result
如果是修改数据库中的数据:
db.commit()
db.close()
return rs
2. 关于配置文件
首先,别忘了import ConfigParser
##写配置信息
def SetConfig(self, FilePath, section, key, value):
config = ConfigParser.ConfigParser()
config.readfp(open(FilePath, "r"))
config.set(section, key, value)
config.write(open(FilePath, "w"))
return True
##读取配置信息
def GetConfig(self, FilePath, section = "", key = ""):
config = ConfigParser.ConfigParser()
config.readfp(open(FilePath, "r"))
try:
value = config.get(section, key)except:
value = ""
if value:
value = value.decode("gbk")
return value