'''0117项目需求
1登陆,加密,锁定账户
2图书查看
3添加图书信息
4修改图书价格
5删除(软删除,0 1代表2种状态)
增删改查
'''
'''import xlrd#读取
#book = xlrd.open_workbook("C://testk.xls")
book = xlrd.open_workbook(r'C:\Users\KUBAYAXI\Desktop\testk.xls')
sheet1 = book.sheet_by_index(2)#根据下标读取工作表格
#sheet1 = book.sheet_by_name("test1")?
r = sheet1.nrows#获取有效行数
c = sheet1.ncols#获取列数
for i in range(1,r):
for j in range(c):
#print(sheet1.cell(i,j).value," ",end="")'''
'''#改写数据,
import xlrd,xlwt
from xlutils import copy
book = xlrd.open_workbook(r'C:\Users\KUBAYAXI\Desktop\testk.xls')
book_copy = copy.copy(book)#建立副本?
sheet = book_copy.get_sheet(2)
#添加内容
sheet.write(2,1,"霍金旭")#(2,1)是坐标,"添加的内容"
book_copy.save("testu.xls")'''
#
import xlwt
#只能写不能读
stus = [['姓名', '年龄', '性别', '分数'],
['mary', 20, '女', 89.9],
['mary', 20, '女', 89.9],
['mary', 20, '女', 89.9],
['mary', 20, '女', 89.9]]
book = xlwt.Workbook()#新建一个EXCEL
sheet = book.add_sheet('case1_sheet')#添加一个sheet项
row = 0
for stu in stus:
col = 0
for s in stu:
sheet.write(row,col,s)
col += 1
row += 1
book.save('stu_1.xls')
## 模块和def
‘’‘print(“这是一个特别好的计算器”)
print(“这是一个很low 的计算器”)’’’
def add(a,b):
return (a+b)
def sub(a,b):
return (a-b)
def mul(a,b):
return (a*b)
def p():
if name==“main”:
print(“计算机很low”)
else:
print(“计算机很好”)
#p( )
‘’‘def HaveFun():
if name == ‘main’:
print(‘I am in my domain,my name is %s’ % name)
else:
print(‘Someone else calls me!,my name is %s’ % name)
HaveFun()’’’
import practice0117 as p17
a = p17.add(1,5)
print(a)
#函数定义def
‘’‘def abs(a):
if a < 0:
print(-a)
else:
print(a)
abs(-1)’’’
‘’‘def 函数名(参数)
函数体
return’’’
‘’‘def add(a,b):
print(a+b)
add(3,4)
def showP(person):
for item in person:
print(item)
p = [“Lisa”,175,47]
showP§’’’
#模块:文件名.py;调用模块关键字import,from,as,库,文件夹.
#from 路径 import 模块 as 别名; name
‘’‘import practice0117 as p0117
p0117.p()
‘’’
‘’‘import practice0117
a = practice0117.sub(2,3)
print(a)’’’
#as起别名
‘’‘import practice
import sys
print(sys.path)’’’
方式一:转义的方式
'd:\\a.txt'
方式二:显式声明字符串不用转义
'd:r\a.txt'
方式三:使用Linux的路径/
'd:/a.txt'