python3 员工信息表

这是最后一条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

### 使用 Python 中的哈希实现员工信息查找功能 在 Python 中,可以通过自定义类或直接使用字典来实现员工信息的查找功能。以下是一个完整的实现方案。 #### 自定义哈希类实现 通过创建一个哈希类,可以手动管理员工信息的存储和查找。以下是具体的实现代码: ```python class EmployeeHashTable: def __init__(self, size=100): # 初始化哈希的大小,默认为 100 self.size = size # 创建一个空列作为槽位数组 self.slots = [None] * self.size # 记录当前哈希中的键值对数量 self.count = 0 def _hash(self, key): # 哈希函数,将键转换为索引 return hash(key) % self.size def add_employee(self, employee_id, employee_info): # 插入员工信息 index = self._hash(employee_id) if self.slots[index] is None: # 如果槽位为空,则直接插入 self.slots[index] = [(employee_id, employee_info)] else: # 如果槽位已有数据,则检查是否存在相同的键 for i, (eid, info) in enumerate(self.slots[index]): if eid == employee_id: self.slots[index][i] = (employee_id, employee_info) # 更新值 return self.slots[index].append((employee_id, employee_info)) # 添加新键值对 self.count += 1 def find_employee(self, employee_id): # 查找员工信息 index = self._hash(employee_id) if self.slots[index] is not None: for eid, info in self.slots[index]: if eid == employee_id: return info # 返回找到的员工信息 raise KeyError(f"Employee ID &#39;{employee_id}&#39; not found") # 员工ID不存在时抛出异常 def delete_employee(self, employee_id): # 删除员工信息 index = self._hash(employee_id) if self.slots[index] is not None: for i, (eid, info) in enumerate(self.slots[index]): if eid == employee_id: del self.slots[index][i] self.count -= 1 return raise KeyError(f"Employee ID &#39;{employee_id}&#39; not found") # 员工ID不存在时抛出异常 ``` #### 使用示例 以下是如何使用上述 `EmployeeHashTable` 类的示例代码: ```python # 创建一个员工哈希实例 employee_ht = EmployeeHashTable() # 插入员工信息 employee_ht.add_employee("E123", {"name": "Alice", "department": "HR", "position": "Manager"}) employee_ht.add_employee("E456", {"name": "Bob", "department": "Engineering", "position": "Developer"}) # 查找员工信息 print(employee_ht.find_employee("E123")) # 输出: {&#39;name&#39;: &#39;Alice&#39;, &#39;department&#39;: &#39;HR&#39;, &#39;position&#39;: &#39;Manager&#39;} print(employee_ht.find_employee("E456")) # 输出: {&#39;name&#39;: &#39;Bob&#39;, &#39;department&#39;: &#39;Engineering&#39;, &#39;position&#39;: &#39;Developer&#39;} # 删除员工信息 employee_ht.delete_employee("E123") try: print(employee_ht.find_employee("E123")) # 抛出 KeyError except KeyError as e: print(e) # 输出: Employee ID &#39;E123&#39; not found ``` #### 使用字典实现 如果不需要手动管理哈希,可以直接使用 Python 的内置字典来实现员工信息的查找功能。以下是具体实现代码: ```python class EmployeeDictionary: def __init__(self): # 初始化一个空字典 self.employees = {} def add_employee(self, employee_id, employee_info): # 插入员工信息 self.employees[employee_id] = employee_info def find_employee(self, employee_id): # 查找员工信息 return self.employees.get(employee_id, f"Employee ID &#39;{employee_id}&#39; not found") def delete_employee(self, employee_id): # 删除员工信息 if employee_id in self.employees: del self.employees[employee_id] else: raise KeyError(f"Employee ID &#39;{employee_id}&#39; not found") ``` #### 使用示例 以下是如何使用上述 `EmployeeDictionary` 类的示例代码: ```python # 创建一个员工字典实例 employee_dict = EmployeeDictionary() # 插入员工信息 employee_dict.add_employee("E123", {"name": "Alice", "department": "HR", "position": "Manager"}) employee_dict.add_employee("E456", {"name": "Bob", "department": "Engineering", "position": "Developer"}) # 查找员工信息 print(employee_dict.find_employee("E123")) # 输出: {&#39;name&#39;: &#39;Alice&#39;, &#39;department&#39;: &#39;HR&#39;, &#39;position&#39;: &#39;Manager&#39;} print(employee_dict.find_employee("E456")) # 输出: {&#39;name&#39;: &#39;Bob&#39;, &#39;department&#39;: &#39;Engineering&#39;, &#39;position&#39;: &#39;Developer&#39;} # 删除员工信息 employee_dict.delete_employee("E123") print(employee_dict.find_employee("E123")) # 输出: Employee ID &#39;E123&#39; not found ``` ### 实现说明 1. **自定义哈希**:通过手动实现哈希类,可以更灵活地控制哈希的行为[^3]。 2. **字典实现**:利用 Python 内置的字典数据结构,可以快速实现员工信息的存储和查找功能[^4]。 3. **冲突解决**:在自定义哈希中,采用链法解决哈希冲突问题[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值