python3 员工信息表

2019-04-20 08:52:54来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

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

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

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

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

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

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

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

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

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

  


 

员工信息表

题目:

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

staff_list文件如下:

1,alex,22,13651054608,IT
2,egon,23,133043202533,teacher
3,nezha,25,1333235322,IT
代码:
  1 #!usr/bin/env/ python
  2 # -*- coding:utf-8 -*-
  3 # Author: XiaoFeng
  4 import os
  5 li = ["id", "name", "age", "phone", "job"]
  6 flag = False
  7 staff_id = None
  8 number = "xiaofeng"
  9 word = "123456"
 10 
 11 
 12 def login(func):
 13     def inner():
 14         global flag
 15         if not flag:
 16             print("如想操作员工信息,请先等录:")
 17             account = input("请输入您的账号:").strip()
 18             password = input("请输入您的密码:").strip()
 19             if account == number and password == word:
 20                 flag = True
 21                 print("登陆成功!")
 22                 res = func()
 23                 return res
 24             else:
 25                 print("账号或密码错误,登陆失败!")
 26         else:
 27             res = func()
 28             return res
 29     return inner
 30 
 31 
 32 def handle(content_1):
 33     if "select" or "set" in content_1 and "where" in content_1:
 34         info_start = content_1.index("t") + 1
 35         info_end = content_1.index("where") - 1
 36         info = content_1[info_start:info_end].strip()
 37         condition = content_1[info_end + 6:].strip()
 38         return info, condition
 39     else:
 40         print("输入错误!")
 41 
 42 
 43 def seek():
 44     content = input("请输入操作:(如select name, age where age>22)").strip().lower()
 45     if content.startswith("select") and "where" in content:
 46         handle_str_1 = handle(content)
 47         out_list = []
 48         for p in li:
 49             if p in handle_str_1[1]:
 50                 if ">" in handle_str_1[1]:
 51                     info_list = handle_str_1[0].split(",")
 52                     str_info = " ".join(info_list)
 53                     info_list = str_info.split()             # 去字符串内空格
 54                     index_0 = handle_str_1[1].index(">")
 55                     character = handle_str_1[1][:index_0].strip()
 56                     num = handle_str_1[1][index_0 + 1:].strip()
 57                     if num.isdigit():
 58                         num = int(num)
 59                         with open("staff_list", "r", encoding="utf-8") as f:
 60                             for line in f:
 61                                 if not line.isspace():
 62                                     line_list = line.strip().split(",")
 63                                     character_value = int(line_list[li.index(character)])
 64                                     if character_value > num:
 65                                         if handle_str_1[0].strip() == "*":
 66                                             out = " ".join(line_list)
 67                                             print(out)
 68                                             out_list.clear()
 69                                         else:
 70                                             for n in info_list:
 71                                                 out_list.append(line_list[li.index(n)])
 72                                             out = " ".join(out_list)
 73                                             print(out)
 74                                             out_list.clear()
 75                     else:
 76                         print("请输入数字!")
 77                 elif "<" in handle_str_1[1]:
 78                     info_list = handle_str_1[0].split(",")
 79                     str_info = " ".join(info_list)
 80                     info_list = str_info.split()
 81                     index_1 = handle_str_1[1].index("<")
 82                     character = handle_str_1[1][:index_1].strip()
 83                     num = handle_str_1[1][index_1 + 1:].strip()
 84                     if num.isdigit():
 85                         num = int(num)
 86                         with open("staff_list", "r", encoding="utf-8") as f:
 87                             for line in f:
 88                                 if not line.isspace():
 89                                     line_list = line.strip().split(",")
 90                                     character_value = int(line_list[li.index(character)])
 91                                     if character_value < num:
 92                                         if handle_str_1[0].strip() == "*":
 93                                             out = " ".join(line_list)
 94                                             print(out)
 95                                             out_list.clear()
 96                                         else:
 97                                             for n in info_list:
 98                                                 out_list.append(line_list[li.index(n)])
 99                                             out = " ".join(out_list)
100                                             print(out)
101                                             out_list.clear()
102                     else:
103                         print("请输入数字!")
104                 elif "=" in handle_str_1[1]:
105                     info_list = handle_str_1[0].split(",")
106                     str_info = " ".join(info_list)
107                     info_list = str_info.split()
108                     index_2 = handle_str_1[1].index("=")
109                     character = handle_str_1[1][:index_2].strip()
110                     num = handle_str_1[1][index_2 + 1:].strip()
111                     if num.isdigit():
112                         num = int(num)
113                         with open("staff_list", "r", encoding="utf-8") as f:
114                             for line in f:
115                                 if not line.isspace():
116                                     line_list = line.strip().split(",")
117                                     character_value = int(line_list[li.index(character)])
118                                     if num == character_value:
119                                         if handle_str_1[0].strip() == "*":
120                                             out = " ".join(line_list)
121                                             print(out)
122                                             out_list.clear()
123                                         else:
124                                             for n in info_list:
125                                                 out_list.append(line_list[li.index(n)])
126                                             out = " ".join(out_list)
127                                             print(out)
128                                             out_list.clear()
129                     else:
130                         with open("staff_list", "r", encoding="utf-8") as f:
131                             for line in f:
132                                 if not line.isspace():
133                                     line_list = line.strip().split(",")
134                                     character_value = line_list[li.index(character)]
135                                     if num == character_value:
136                                         if handle_str_1[0].strip() == "*":
137                                             out = " ".join(line_list)
138                                             print(out)
139                                             out_list.clear()
140                                         else:
141                                             for n in info_list:
142                                                 out_list.append(line_list[li.index(n)])
143                                             out = " ".join(out_list)
144                                             print(out)
145                                             out_list.clear()
146                 elif "like" in handle_str_1[1]:
147                     info_list = handle_str_1[0].split(",")
148                     str_info = " ".join(info_list)
149                     info_list = str_info.split()
150                     index_3 = handle_str_1[1].index("like")
151                     character = handle_str_1[1][:index_3].strip()
152                     num = handle_str_1[1][index_3 + 4:].strip()
153                     with open("staff_list", "r", encoding="utf-8") as f:
154                         for line in f:
155                             if not line.isspace():
156                                 line_list = line.strip().split(",")
157                                 character_value = line_list[li.index(character)]
158                                 if num in character_value:
159                                     if handle_str_1[0].strip() == "*":
160                                         out = " ".join(line_list)
161                                         print(out)
162                                         out_list.clear()
163                                     else:
164                                         for n in info_list:
165                                             out_list.append(line_list[li.index(n)])
166                                         out = " ".join(out_list)
167                                         print(out)
168                                         out_list.clear()
169                 else:
170                     print("\033[31;1m您输入的条件不符合规范!\033[0m")
171     else:
172         print("请输入正确的操作语句!")
173 
174 
175 @login
176 def add():
177     global staff_id
178     if not staff_id:
179         if os.path.getsize("staff_list") == 0:
180             staff_id = 0
181         else:
182             d = 0
183             with open("staff_list", "r", encoding="utf-8") as f:
184                 for line in f:
185                     if not line.isspace():
186                         line_list = line.strip().split(",")
187                         print(line_list)
188                         if line_list[0]:
189                             d = line_list[0]
190                             print(d)
191             staff_id = int(d)
192     print("\033[41;1m请按提示输入信息\033[0m".center(39, "*"))
193     new_staff = []
194     for a in li[1:]:
195         staff_info = input("请输入新员工的%s:" % a).strip()
196         new_staff.append(staff_info)
197     new_staff_str = ",".join(new_staff)
198     staff_id += 1
199     id_str = str(staff_id)
200     final_str = id_str + "," + new_staff_str + "\n"
201     with open("staff_list", "a", encoding="utf-8") as f:
202         f.write(final_str)
203     print("您添加的信息为:{}".format(final_str))
204 
205 
206 @login
207 def delete():
208     id_delete = input("请输入要删除员工的id号:")
209     with open("staff_list", "r", encoding="utf-8") as f1, \
210             open("staff_list_bak", "w", encoding="utf-8") as f2:
211         for line in f1:
212             if not line.isspace():
213                 line_list = line.strip().split(",")
214                 if id_delete == line_list[0]:
215                     continue
216             f2.write(line)
217     os.remove("staff_list")
218     os.rename("staff_list_bak", "staff_list")
219     print("删除成功!")
220 
221 
222 @login
223 def modify():
224     content = input("请输入要修改的内容(如set 列名=“新的值” where id=x)").strip()
225     handle_str = handle(content)
226     info_list = handle_str[0].split(",")
227     str_info = " ".join(info_list)
228     info_list = str_info.split()       # 去字符串内空格
229     index_2 = handle_str[1].index("=")
230     character = handle_str[1][:index_2].strip()
231     num = handle_str[1][index_2 + 1:].strip()
232     if num.isdigit():
233         num_int = int(num)
234         with open("staff_list", "r", encoding="utf-8") as f1, \
235                 open("staff_list_bak", "w", encoding="utf-8") as f2:
236             for line in f1:
237                 if not line.isspace():
238                     line_list = line.strip().split(",")
239                     character_value = int(line_list[li.index(character)])
240                     if num_int == character_value:
241                         for c in info_list:
242                             index_1 = c.index("=")
243                             set_key = c[:index_1].strip()
244                             set_value = c[index_1 + 1:].strip()
245                             line_list[li.index(set_key)] = set_value
246                             line = ",".join(line_list)
247                 f2.write(line)
248         os.remove("staff_list")
249         os.rename("staff_list_bak", "staff_list")
250     else:
251         print("请输入正确语句!")
252 
253 
254 operate_list = ["查找", "新增", "删除", "修改"]
255 while True:
256     print("-" * 50)
257     for index, i in enumerate(operate_list):
258         print(index, "\t", i)
259     choice = input("请输入您个的选择编号:").strip()
260     if choice.isdigit() and choice == "0":
261         seek()
262     elif choice.isdigit() and choice == "1":
263         add()
264     elif choice.isdigit() and choice == "2":
265         delete()
266     elif choice.isdigit() and choice == "3":
267         modify()
268     else:
269         print("请按要求输入编号")

 





原文链接:https://www.cnblogs.com/xf1262048067/p/10739410.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Django—Form、ModelForm

下一篇:Python 强制停止多线程运行