向文件中寫(xiě)入數(shù)據(jù)
file = open('a.txt','w',encoding='utf-8')
file.write("114514")
file.close()
讀取文件中的數(shù)據(jù)
file = open('a.txt','r',encoding='utf-8')
a = file.read()
print(a)
file.close()
讀取excle表中的數(shù)據(jù)
#導(dǎo)出excle表后,進(jìn)入文件左上角文件保存一下
import xlrd
data = xlrd.open_workbook('student.xls')
a = data.sheets()[0]
nrows = a.nrows
ncols = a.ncols
for i in range(1,nrows):
for j in range(1,ncols):
print(a.cell(i,j))
mysql操作
需要先下載下方的插件
圖片.png
class Person():
def __init__(self,a,b,c):
self.a = a
self.b = b
self.c = c
import pymysql
con = pymysql.connect(host='127.0.0.1',user='root',password='123456',database='1907test')
sno = con.cursor()
# 查詢(xún)
sno.execute('select * from course')
a = sno.fetchall()
print(a[0])
b = a[0]
#查詢(xún)出來(lái)把數(shù)據(jù)填入實(shí)體類(lèi)
person = Person(b[0],b[1],b[2])
print(person.a,person.b,person.c)
sno.close()
con.close()
# 刪除
a = sno.execute('delete from student where sno = 108')
if a > 0:
print('刪除成功')
else :
print('刪除失敗')
sno.close()
con.close()
# 修改
a = sno.execute('update student set sname = "123" where sno = 105')
con.commit()
if a > 0:
print('修改成功')
else :
print('修改失敗')
sno.close()
con.close()