常用的功能
一、随机数生成
import random
#生成1-1000之间的伪随机数 num = random.randint(1,1000)
二、读文件
read = open("c:\\text.txt","r") lines = read.readlines() for line in lines: print line
三、写文件
w = open("c:\\test.txt","r+") w.write("123")
四、连接数据库
import MySQLdb conn = MySQLdb.connect (host='localhost',databse='test',user='test',password='123') sql= conn.cursor() sql.execute("select * from test") print sql.rowcount