python3 employee information table

Keywords: Python encoding

This is the last NLP...Come on

Twelve, motivation and emotion are always right, but behavior is ineffective

Motivation is subconscious and always positive.The subconscious never harms itself, only mistakenly assumes that an action satisfies that motivation without knowing that there is a possibility of doing something else.

Emotions always give us a push. Emotions make us learn something about it, and when we learn it, it disappears.

We can accept a person's motivation and emotion, but not his behavior.

Acceptance motivation and emotion is accepting that person, who will also feel that you are accepting him, and will therefore be more willing to let you guide him to change.

Any action is not equal to one person.

Behavior is unacceptable because it has no effect. Finding a better way is a common goal for both people to have good communication and relationship with each other.

One way to find a better way to do this is to look at the values behind your motivation.

  

 

Employee Information Sheet

Title:

Then there's the code. Wow, if you tap, you'll find a lot of things and details that you've never noticed before.

The staff_list file is as follows:

1,alex,22,13651054608,IT
2,egon,23,133043202533,teacher
3,nezha,25,1333235322,IT
Code:
  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("If you want to operate on employee information, please wait and record first:")
 17             account = input("Please enter your account number:").strip()
 18             password = input("Please enter your password:").strip()
 19             if account == number and password == word:
 20                 flag = True
 21                 print("Landing success!")
 22                 res = func()
 23                 return res
 24             else:
 25                 print("Logon failed because of incorrect account or password!")
 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("Input error!")
 41 
 42 
 43 def seek():
 44     content = input("Please enter an action:(as 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()             # String space removal
 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("Please enter a number!")
 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("Please enter a number!")
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 The conditions you entered do not conform to the specification!\033[0m")
171     else:
172         print("Please enter the correct operation statement!")
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 Please enter information as prompted\033[0m".center(39, "*"))
193     new_staff = []
194     for a in li[1:]:
195         staff_info = input("Please enter a new employee's%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("The information you added is:{}".format(final_str))
204 
205 
206 @login
207 def delete():
208     id_delete = input("Please enter the id Number:")
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("Delete successful!")
220 
221 
222 @login
223 def modify():
224     content = input("Please enter what you want to modify(as set Column Name="New Value" 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()       # String space removal
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("Please enter the correct statement!")
252 
253 
254 operate_list = ["lookup", "Newly added", "delete", "modify"]
255 while True:
256     print("-" * 50)
257     for index, i in enumerate(operate_list):
258         print(index, "\t", i)
259     choice = input("Please enter your choice number:").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("Please enter the number as required")

 




Posted by egroeg41 on Sat, 11 May 2019 12:42:28 -0700