求解释一下修改和删除原理
import os.pathimport pandas as pd
import xlrd
import xlwt
from xlutils.copy import copy
# 创建excel表格
def create():
wb = xlwt.Workbook('信息表.xls')
sh1 = wb.add_sheet('Sheet1')
# 添加信息
sh1.write(0, 0, '身份证件号')
sh1.write(0, 1, '姓名')
sh1.write(0, 2, '房间号')
sh1.write(0, 3, '房费')
sh1.write(0, 4, '押金')
# 保存
wb.save('信息表.xls')
# 查询住户信息
def Inquire():
Ch1 = input("请输入身份证件号:")
readbook = xlrd.open_workbook('信息表.xls')
sh1 = readbook.sheet_by_index(0)
# 循环信息表的所有行
for row in sh1.get_rows():
ID = row# 身份证所在的列
product_value = ID.value
# 判断输入身份证的信息
if product_value == Ch1:
if product_value != '身份证件号':# 排除第一行
price_column = row# 身份证所在的列
ID_card = price_column.value
price_column = row# 姓名所在的列
name = price_column.value
price_column = row# 房间号所在的列
room_number = price_column.value
price_column = row# 房费所在的列
Room_rate = price_column.value
price_column = row# 押金所在的列
deposit = price_column.value
# 打印
print(f"身份证件号:{ID_card}姓名:{name}房间号:{room_number}房费:{Room_rate}押金:{deposit}")
# 修改住户信息
def modify():
Inquire()
Ch1 = input("再次确认修改住户信息(是/否):")
while True:
if Ch1 == "是":
# 是的话就修改
break
elif Ch1 == "否":
# 不是的话就退出
break
# 添加住户
def Add_to():
# 打开excel表格
readbook = xlrd.open_workbook('信息表.xls')
wb = copy(readbook)
# 获取最后一行并加一行
excel = pd.read_excel(readbook)
line = len(excel) + 1
# 选取第一个表单
sh1 = wb.get_sheet(0)
# 输入数据
num = input("身份证件号:")
name = input("姓名:")
num2 = input("房间号:")
num3 = input("房费:")
num4 = input("押金:")
# 导入到excel表格里
sh1.write(line, 0, num)
sh1.write(line, 1, name)
sh1.write(line, 2, num2)
sh1.write(line, 3, num3)
sh1.write(line, 4, num4)
# 保存
wb.save('信息表.xls')
# 删除住户
def delete():
Inquire()
Ch1 = input("再次删除住户信息(是/否):")
while True:
if Ch1 == "是":
# 是的话就删除
break
elif Ch1 == "否":
# 不是的话就退出
break
# 选择
def select():
for i in range(3):
Ch = input("请选择:")
if Ch == "1":
Inquire()
break
elif Ch == "2":
modify()
break
elif Ch == "3":
Add_to()
break
elif Ch == "4":
delete()
break
elif Ch == "5":
exit(1)
else:
print("输入错误")
# 判断是否有信息表
if not os.path.exists('信息表.xls'):
create()
print("创建成功")
Add_to()
else:
print("表格已存在")
print("1:查询住户信息2:修改住户信息 3:添加住户 4:删除住户 5:退出")
select()
如何弄原理应该怎么弄,弄了半天还是没有头绪 你这样光发代码我都不知道你要干什么啊{:10_277:} 是不是把一个变量重新赋值? weiter 发表于 2020-8-14 17:44
是不是把一个变量重新赋值?
谁知道呢{:10_250:} 陈尚涵 发表于 2020-8-14 17:45
谁知道呢
是啊,谁知道呢{:10_250:} weiter 发表于 2020-8-14 17:46
是啊,谁知道呢
呵呵
看之前帖子的意思,这些代码不是你自己弄的么?还需要别人来解释你自己写的代码?
https://fishc.com.cn/forum.php?mod=viewthread&tid=177637&page=1#pid4910030 @zltzlt 把这个帖子也关了吧…… 永恒的蓝色梦想 发表于 2020-8-16 10:00
@zltzlt 把这个帖子也关了吧……
好的
页:
[1]