python3 员工信息表

这是最后一条NLP了......来吧

十二,动机和情绪总不会错,只是行为没有效果而已

动机在潜意识里,总是正面的。潜意识从来不会伤害自己,只会误会的以为某行为可以满足该动机,而又不知道有其他做法的可能。

情绪总是给我们一份推动力,情绪使我们在该事情之中有所学习,学到了,情绪便会消失。

我们可以接受一个人的动机和情绪,同时不接受他的行为。

接受动机和情绪,便是接受那个人,那个人也会感觉出你对他的接受,因而更肯让你去引导他做出改变。

任何一次行为不等于一个人。

行为不能接受,是因为没有效果,找出更好的做法,是两个人共同的目标,能使两个人有跟好的沟通和关系。

找出更好的做法的方法之一是追查动机背后的价值观。


员工信息表

题目:

python3 员工信息表

接下来是代码了,哇果然是敲着敲着就发现好多以前从来没注意的东西,好多细节。

staff_list文件如下:

1,alex,22,13651054608,IT
2,egon,23,133043202533,teacher
3,nezha,25,1333235322,IT
代码:
 #!usr/bin/env/ python
# -*- coding:utf-8 -*-
# Author: XiaoFeng
import os
li = ["id", "name", "age", "phone", "job"]
flag = False
staff_id = None
number = "xiaofeng"
word = "" def login(func):
def inner():
global flag
if not flag:
print("如想操作员工信息,请先等录:")
account = input("请输入您的账号:").strip()
password = input("请输入您的密码:").strip()
if account == number and password == word:
flag = True
print("登陆成功!")
res = func()
return res
else:
print("账号或密码错误,登陆失败!")
else:
res = func()
return res
return inner def handle(content_1):
if "select" or "set" in content_1 and "where" in content_1:
info_start = content_1.index("t") + 1
info_end = content_1.index("where") - 1
info = content_1[info_start:info_end].strip()
condition = content_1[info_end + 6:].strip()
return info, condition
else:
print("输入错误!") def seek():
content = input("请输入操作:(如select name, age where age>22)").strip().lower()
if content.startswith("select") and "where" in content:
handle_str_1 = handle(content)
out_list = []
for p in li:
if p in handle_str_1[1]:
if ">" in handle_str_1[1]:
info_list = handle_str_1[0].split(",")
str_info = " ".join(info_list)
info_list = str_info.split() # 去字符串内空格
index_0 = handle_str_1[1].index(">")
character = handle_str_1[1][:index_0].strip()
num = handle_str_1[1][index_0 + 1:].strip()
if num.isdigit():
num = int(num)
with open("staff_list", "r", encoding="utf-8") as f:
for line in f:
if not line.isspace():
line_list = line.strip().split(",")
character_value = int(line_list[li.index(character)])
if character_value > num:
if handle_str_1[0].strip() == "*":
out = " ".join(line_list)
print(out)
out_list.clear()
else:
for n in info_list:
out_list.append(line_list[li.index(n)])
out = " ".join(out_list)
print(out)
out_list.clear()
else:
print("请输入数字!")
elif "<" in handle_str_1[1]:
info_list = handle_str_1[0].split(",")
str_info = " ".join(info_list)
info_list = str_info.split()
index_1 = handle_str_1[1].index("<")
character = handle_str_1[1][:index_1].strip()
num = handle_str_1[1][index_1 + 1:].strip()
if num.isdigit():
num = int(num)
with open("staff_list", "r", encoding="utf-8") as f:
for line in f:
if not line.isspace():
line_list = line.strip().split(",")
character_value = int(line_list[li.index(character)])
if character_value < num:
if handle_str_1[0].strip() == "*":
out = " ".join(line_list)
print(out)
out_list.clear()
else:
for n in info_list:
out_list.append(line_list[li.index(n)])
out = " ".join(out_list)
print(out)
out_list.clear()
else:
print("请输入数字!")
elif "=" in handle_str_1[1]:
info_list = handle_str_1[0].split(",")
str_info = " ".join(info_list)
info_list = str_info.split()
index_2 = handle_str_1[1].index("=")
character = handle_str_1[1][:index_2].strip()
num = handle_str_1[1][index_2 + 1:].strip()
if num.isdigit():
num = int(num)
with open("staff_list", "r", encoding="utf-8") as f:
for line in f:
if not line.isspace():
line_list = line.strip().split(",")
character_value = int(line_list[li.index(character)])
if num == character_value:
if handle_str_1[0].strip() == "*":
out = " ".join(line_list)
print(out)
out_list.clear()
else:
for n in info_list:
out_list.append(line_list[li.index(n)])
out = " ".join(out_list)
print(out)
out_list.clear()
else:
with open("staff_list", "r", encoding="utf-8") as f:
for line in f:
if not line.isspace():
line_list = line.strip().split(",")
character_value = line_list[li.index(character)]
if num == character_value:
if handle_str_1[0].strip() == "*":
out = " ".join(line_list)
print(out)
out_list.clear()
else:
for n in info_list:
out_list.append(line_list[li.index(n)])
out = " ".join(out_list)
print(out)
out_list.clear()
elif "like" in handle_str_1[1]:
info_list = handle_str_1[0].split(",")
str_info = " ".join(info_list)
info_list = str_info.split()
index_3 = handle_str_1[1].index("like")
character = handle_str_1[1][:index_3].strip()
num = handle_str_1[1][index_3 + 4:].strip()
with open("staff_list", "r", encoding="utf-8") as f:
for line in f:
if not line.isspace():
line_list = line.strip().split(",")
character_value = line_list[li.index(character)]
if num in character_value:
if handle_str_1[0].strip() == "*":
out = " ".join(line_list)
print(out)
out_list.clear()
else:
for n in info_list:
out_list.append(line_list[li.index(n)])
out = " ".join(out_list)
print(out)
out_list.clear()
else:
print("\033[31;1m您输入的条件不符合规范!\033[0m")
else:
print("请输入正确的操作语句!") @login
def add():
global staff_id
if not staff_id:
if os.path.getsize("staff_list") == 0:
staff_id = 0
else:
d = 0
with open("staff_list", "r", encoding="utf-8") as f:
for line in f:
if not line.isspace():
line_list = line.strip().split(",")
print(line_list)
if line_list[0]:
d = line_list[0]
print(d)
staff_id = int(d)
print("\033[41;1m请按提示输入信息\033[0m".center(39, "*"))
new_staff = []
for a in li[1:]:
staff_info = input("请输入新员工的%s:" % a).strip()
new_staff.append(staff_info)
new_staff_str = ",".join(new_staff)
staff_id += 1
id_str = str(staff_id)
final_str = id_str + "," + new_staff_str + "\n"
with open("staff_list", "a", encoding="utf-8") as f:
f.write(final_str)
print("您添加的信息为:{}".format(final_str)) @login
def delete():
id_delete = input("请输入要删除员工的id号:")
with open("staff_list", "r", encoding="utf-8") as f1, \
open("staff_list_bak", "w", encoding="utf-8") as f2:
for line in f1:
if not line.isspace():
line_list = line.strip().split(",")
if id_delete == line_list[0]:
continue
f2.write(line)
os.remove("staff_list")
os.rename("staff_list_bak", "staff_list")
print("删除成功!") @login
def modify():
content = input("请输入要修改的内容(如set 列名=“新的值” where id=x)").strip()
handle_str = handle(content)
info_list = handle_str[0].split(",")
str_info = " ".join(info_list)
info_list = str_info.split() # 去字符串内空格
index_2 = handle_str[1].index("=")
character = handle_str[1][:index_2].strip()
num = handle_str[1][index_2 + 1:].strip()
if num.isdigit():
num_int = int(num)
with open("staff_list", "r", encoding="utf-8") as f1, \
open("staff_list_bak", "w", encoding="utf-8") as f2:
for line in f1:
if not line.isspace():
line_list = line.strip().split(",")
character_value = int(line_list[li.index(character)])
if num_int == character_value:
for c in info_list:
index_1 = c.index("=")
set_key = c[:index_1].strip()
set_value = c[index_1 + 1:].strip()
line_list[li.index(set_key)] = set_value
line = ",".join(line_list)
f2.write(line)
os.remove("staff_list")
os.rename("staff_list_bak", "staff_list")
else:
print("请输入正确语句!") operate_list = ["查找", "新增", "删除", "修改"]
while True:
print("-" * 50)
for index, i in enumerate(operate_list):
print(index, "\t", i)
choice = input("请输入您个的选择编号:").strip()
if choice.isdigit() and choice == "":
seek()
elif choice.isdigit() and choice == "":
add()
elif choice.isdigit() and choice == "":
delete()
elif choice.isdigit() and choice == "":
modify()
else:
print("请按要求输入编号")

上一篇:python---进程、线程


下一篇:struts2官方 中文教程 系列八:异常处理