#!/usr/bin/env python
# -*- coding:utf-8 -*-
#-----------------------------------------------------
# File: function.py
# Date: 2008-09-01
# Description:
#-----------------------------------------------------
__version__ = '1.0'
__author__ = 'Wubin Qu <quwubin@gmail.com> @ZCGLAB @BMI @CHINA'
def read_from_file(file_name):
fh = open(file_name)
file_content = fh.read()
fh.close()
return file_content
def write_to_file(file_name, file_content, model):
fh = open(file_name, model)
fh.write(file_content)
fh.close()
def connect_mysql(host, user, passwd, dbname):
''' Connect to the MySQL database '''
import MySQLdb
db = MySQLdb.Connection(host, user, passwd, dbname)
cur = db.cursor()
return cur, db
def debug(s):
fh = open('debug.tmp', 'a')
fh.write(str(s))
fh.write('/n')
fh.close()
def close_mysql(cur, db):
''' Close the database '''
cur.close()
db.close()
def main():
host, user, passwd, dbname = 'localhost', 'quwb', 'wangting', 'abmart'
cur, db = connect_mysql(host, user, passwd, dbname)
close_mysql(cur, db)
if __name__ == '__main__':
main()
function.py模块,里面有经常使用到的一些函数,可以向里面添加你的常用函数和对象
最新推荐文章于 2022-02-10 16:25:47 发布