|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 wei_Y 于 2014-12-19 18:08 编辑
- import os
- import os.path
- while True:
- #进入之前要验证用户名与密码
- user = input('Please input username:').strip()
- while user == '' or user != 'roy':
- user = input('Please input username:').strip()
- continue
- else:
- password = input('Please input password:').strip()
- while password == '' or password != 'abc':
- password = input('Please input password:').strip()
- continue
- print('Welcome enter system!!!')
-
- #不断循环要操作的项目,输入q或quit就退出
- while True:
- print('1. Add User\n2. Modify User\n3. Del User\n4. Find User\n')
-
- #把文件读出来放到列表
- f = open('content.txt','r')
- li = f.readlines()
- f.close()
- num = 0
- choose = input('Please choose:').strip().lower()
- if choose == 'q' or choose == 'quit':
- print('ByeBye!!')
- break
- #增加用户
- elif choose == '1':
- fadd = open('content.txt','w')
- u = input('Please input id:')
- p = input('Please input name:')
- s = input('Please input sex:')
- d = input('Please input Department:')
- li.append('\n'+u+'\t'+p+'\t'+s+'\t'+d+'\t')
- fadd.writelines(li)
- fadd.flush()
- continue
- #修改文件内容
- elif choose == '2':
- co = 0
- ok = input('Please input old key:')
- nk = input('Please input new key:')
-
- frm = open('content.txt','w')
- for lines in li:
- if ok in li[co]:
- li[co] = li[co].replace(ok,nk)
- co += 1
- frm.writelines(li)
- frm.flush()
- continue
- #删除用户
- elif choose == '3':
- co = 0
- rm = input('Please input remove key index:')
- frm = open('content.txt','w')
- for lines in li:
- if rm in li[co]:
- del li[co]
- co += 1
- frm.writelines(li)
- frm.flush()
- continue
- #查找内容
- elif choose == '4':
- find_name = input('Please input find key words:').strip()
- for line in li:
- if find_name in line:
- print (line)
- num += 1
- else:
- if num == 0:
- print('Not a valid key words!')
- continue
- else:
- print('Find %d data' % num)
- num = 0
- continue
- else:
- print('Input error!')
- continue
- f.close()
- break
复制代码
|
评分
-
查看全部评分
|