然后
import pymysql #导入pymsql模块 #链接数据库,注意port是int型,不是str,所以不要用引号conn = pymysql.connect(user='root',password='root',host='127.0.0.1',port=3306,database='test_demo',use_unicode=True,charset="utf8")#获取游标cursor = conn.cursor()#插入数据,注意看有变量的时候格式cursor.execute("INSERT INTO tieba_user(`uuid`,`user_name`,`user_rank`,`user_level`,`level_status`,`tieba_name`) VALUES (%s,%s,%s,%s,%s,%s)", (user_id, user_name, user_rank, user_level, level_statu, tieba_name))#提交conn.commit()#关闭连接cursor.close()
类似这样
public Dictionary Read(string path) //读txt文件 返回字典{
StreamReader sr = new StreamReader(path,Encoding.Default)
String line
var dic = new Dictionary()
while ((line = sr.ReadLine()) != null)
{
var li= line.ToString().Splite(",")//将一行用,分开成键值对
dic.Add(li.key,li.value)
}
return dic
}
public void Write(string path,Dictionary mydic) //将字典写入txt
{
FileStream fs = new FileStream(path, FileMode.Create)
StreamWriter sw = new StreamWriter(fs)
//开始写入
foreach(var d in mydic)
{
sw.Write(d.key.+","+d.value)//键值对写入,用逗号隔开
}
//清空缓冲区
sw.Flush()
//关闭流
sw.Close()
fs.Close()
}
名称:COLUMN 主要功能:显示所引用
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)