python如何實現(xiàn)員工管理系統(tǒng)-創(chuàng)新互聯(lián)

這篇文章給大家分享的是有關python如何實現(xiàn)員工管理系統(tǒng)的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

在雙臺子等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網(wǎng)站建設、網(wǎng)站設計 網(wǎng)站設計制作按需定制制作,公司網(wǎng)站建設,企業(yè)網(wǎng)站建設,品牌網(wǎng)站制作,營銷型網(wǎng)站,成都外貿網(wǎng)站建設,雙臺子網(wǎng)站建設費用合理。

這是一個簡易的員工管理系統(tǒng),實現(xiàn)最簡單的功能:

1.登錄用戶密碼驗證(錯誤三次自動退出)
2.支持文本員工的搜索、添加、刪除、修改
3.一級層級多個選項、二級層級多個選項,都支持判空、退出、返回上一層級
4.針對刪除和修改有員工當前自動搜索到的結果進行參照修改和特殊提醒是否刪除

用到的基礎知識點比較多:

1.計數(shù)器
2.while True 以及給while做退出層級標記
3.if…elif…else 的嵌套使用
4.continue 和 break 以及簡單函數(shù)定義def
5.鍵盤抓取 raw_input 以及通過 os.system(‘clear')來調用linux中shell下的命令。
6.文本的讀取寫入原理(單讀的不能實際寫入,只能通過轉存文本覆蓋寫入。)
如果是‘a(chǎn)+'則只為讀取并可通過'writelines()'來寫入,是追加寫入
如果是‘w+'則為寫入,可通過‘writelines()'來寫入,是覆蓋寫入
7.列表的構成原理,列表的轉換,列表的定位以及下標獲取 listname.index(line)
8.特別需要注意程序執(zhí)行前后順序以及嚴格的縮進格式

python如何實現(xiàn)員工管理系統(tǒng)

#!/usr/bin/env python
# _*_ coding:utf-8 _*_
import sys
import os

#系統(tǒng)的用戶登錄
#os.system('clear')
time = 0
while True: #this is login
  if time < 3:
    name = raw_input("\033[1mplease input your login account:").strip()
    passwd = raw_input("\033[1mplease input your login password:").strip()
    if len(name) == 0:        #.strip()意為去除空格
      print("\033[31mIt's not allow empty input!\n")
      continue
    elif name == 'zhangjun' and passwd == '123.com':
      print("\033[32mYour account and password right!")
      pass
    else:
      print("\033[31mYour account or password error!")
      time += 1
      continue
    break
  else:
    print("\033[31mYou are wrong three times, has already quit from the system!")
    sys.exit()

#系統(tǒng)的選擇界面
#os.system('clear')
print ('\n')
def display(): #進行登陸后界面的函數(shù)定義,方便在下面的選用層級后,返回上一層時,依然可以看到選擇大屏。
 print("\033[34m########################################################################")
 print("\033[34m\t######### \033[1;32mWelcome to this employee search system!\033[0;34m #########")
 print("\033[34m\t\t#################################################")
 print("\n")
 print("\033[32m\033[1m\t\t\t1\033[33m\033[1m.Search.(you can search the infomation for employee!)\n")
 print("\033[32m\033[1m\t\t\t2\033[33m\033[1m.Add.(Add a user into this employee system!)\n")
 print("\033[32m\033[1m\t\t\t3\033[33m\033[1m.Delete.(Delete a user from this employee system!)\n")
 print("\033[32m\033[1m\t\t\t4\033[33m\033[1m.Modify.(You can modify something infomation in this employee system!)\n")
 print("\033[32m\033[1m\t\t\t5\033[33m\033[1m.Quit.(quit this employee system!)\n")
 print("\n")
 dict ()
#指定文件路徑
path = 'D:\Users\Franzhang\employee_list.txt'
#定義while層級標記break_tag1 = 0 以及登陸初始提示
break_tag1 = 0
while break_tag1 == 0:
 display()
 select_input = raw_input ("\033[37m\033[1mplease input you want to select items:").strip ()
 if len(select_input) == 0:
  continue
 elif select_input == 'quit':
  sys.exit ()
 #選項1進行模糊搜索
 elif int(select_input) == 1:
  # os.system('clear')
  break_tag2 = 0
  while break_tag2 == 0:
   content_open = open (path)
   search_input = raw_input ("please input your need (SEARCH MODE):").strip ()
   for line in content_open:
    if len (search_input) == 0:
     continue
    elif search_input in line:
     print line
    else:
     if search_input == 'all': #展示文本目前所有員工
      print line
     elif search_input == 'quit':
      break_tag2 = 1 #返回上一層級選擇項
 #選項2進行員工信息添加(其實是添加了一行列表)
 elif int(select_input) == 2:
  # os.system('clear')
  content_write = file (path, 'a+') #讀入文本
  break_tag3 = 0
  while break_tag3 == 0:
   addid_input = raw_input ("please input your need (ADD_ID):").strip ()
   if len (addid_input) == 0:
    continue
   elif addid_input == 'quit':
    break_tag3 = 1
    content_write.close () #文本使用完畢后需要關閉,以免占用內存。
    break
   addname_input = raw_input ("please input your need (ADD_NAME):").strip ()
   if len (addid_input) == 0:
    continue
   elif addname_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   addage_input = raw_input ("please input your need (ADD_AGE):").strip ()
   if len (addid_input) == 0:
    continue
   elif addage_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   adddpt_input = raw_input ("please input your need (ADD_DPT):").strip ()
   if len (addid_input) == 0:
    continue
   elif adddpt_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   addphone_input = raw_input ("please input your need (ADD_phone):").strip ()
   if len (addid_input) == 0:
    continue
   elif addphone_input == 'quit':
    break_tag3 = 1
    content_write.close ()
    break
   list_add = [addid_input, '\t', addname_input, '\t', addage_input, '\t', adddpt_input, '\t', addphone_input,'\n'] #將上面的單項錄入寫入列表list_add
   content_write.writelines (list_add) #將列表追加寫入文本
   print("It's already insert the list!")
   continue
 #選項3進行員工刪除
 elif int(select_input) == 3:
  # os.system('clear')
  break_tag4 = 0
  while break_tag4 == 0:
   content_opend = open (path)
   delete_input = raw_input ("please input your need (DELETE):").strip ()
   if len (delete_input) == 0:
    continue
   elif delete_input == 'quit':
    break_tag4 = 1
   for line in content_opend:
    if delete_input in line:
     print line
     sure = raw_input ("Are you sure delete this account line ? (yes/no):").strip ()
     if len (sure) == 0:
      continue
     elif sure == 'yes':
      inside = file (path, 'a+') 
      bebe = inside.readlines () #按行讀入文本并轉換為列表data
      data = list (bebe) 
      for i in data:
       if delete_input in i: 
        w = data.index (i) #獲取輸入的員工在整個文本列表的位置
        del data[w] #刪除單行
      data_in = data #轉存刪除后的文本列表(這個時候被讀取的經(jīng)過刪除后的內容還在內存中。)
      inside.close () #轉存后在關閉文本,否則導致轉存因提前關閉而無效。
      inside_w = file (path, 'w+') #再次以覆蓋寫入方式讀取文本
      inside_w.writelines (data_in) #將剛才轉存的文本寫入
      inside_w.close () #關閉文本后會自動保存寫入
      break
     elif sure == 'no':
      break
    continue
 #選項4進行員工信息更改(整條員工信息的更改)
 elif int(select_input) == 4:
  break_tag5 = 0
  while break_tag5 == 0:
   modify_input = raw_input ("please input your modify item:").strip ()
   if len (modify_input) == 0:
    continue
   elif modify_input == 'quit':
    break
   content_modify = file (path, 'a+')
   modify_line = content_modify.readlines ()
   modata = list (modify_line)
   for i in modata:
    if modify_input in i:
     ms = modata.index (i)#獲取輸入變量的最終列表定位
     print i
     mosure = raw_input ("Are you sure to change this user ? (yes/no):").strip ()
     if len (mosure) == 0:
      continue
     elif mosure == 'yes':
      break_tag6 = 0
      while break_tag6 == 0:
       sureid_input = raw_input ("please input you will change this user id: ").strip ()
       if len(sureid_input) == 0:
        continue
       elif sureid_input == 'quit':
        break
       surename_input = raw_input ("please input you will change this user name:").strip ()
       if len(surename_input) == 0:
        continue
       elif surename_input == 'quit':
        sureid_input = None #此處賦空值,為了防止中途退出,而出現(xiàn)個別寫入
        surename_input = None
        break
       sureage_input = raw_input ("please input you will change this user age:").strip ()
       if len(sureage_input) == 0:
        continue
       elif sureage_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        break
       suredep_input = raw_input ("please input you will change this user department:").strip ()
       if len(suredep_input) == 0:
        continue
       elif suredep_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        suredep_input = None
        break
       surephone_input = raw_input ("please input you will change this user phone:").strip ()
       if len(surephone_input) == 0:
        continue
       elif surephone_input == 'quit':
        sureid_input = None
        surename_input = None
        sureage_input = None
        suredep_input = None
        surephone_input = None
        break
       later_sure = [sureid_input, '\t', surename_input, '\t\t', sureage_input, '\t', suredep_input,'\t', surephone_input, '\n']#將上面的值放入列表
       del modata[ms] #當整個輸入完成以后再進行刪除,防止中途退出未完成狀體的刪除。
       modata_one = modata
       content_modify.close () #這里還是使用了刪除、轉存、重新寫入的原理
       content_modify_list = file (path, 'w+')
       content_modify_list.writelines (modata_one)
       content_modify_list.close ()
       content_modify_list_one = file (path, 'a+')
       content_modify_list_one.writelines (later_sure)
       content_modify_list_one.close ()
       break
     elif mosure == 'quit' or 'no':
      break
 elif int (select_input) == 5:
  print("Thank you for use this employee system, write by franzhang!")
  sys.exit()

employee_list.txt:

python如何實現(xiàn)員工管理系統(tǒng)

感謝各位的閱讀!關于“python如何實現(xiàn)員工管理系統(tǒng)”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

當前文章:python如何實現(xiàn)員工管理系統(tǒng)-創(chuàng)新互聯(lián)
URL鏈接:http://muchs.cn/article42/dhdhec.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、響應式網(wǎng)站、標簽優(yōu)化、手機網(wǎng)站建設、微信公眾號、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)