码迷,mamicode.com
首页 > 编程语言 > 详细

python

时间:2017-01-17 00:11:40      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:功能   匹配   代码   查看   amount   code   ict   gre   log   

#工信息表

(1)作业需求:

现需要对这个员工信息文件,实现增删改查操作


  • 可进行模糊查询,语法至少支持下面3种:
    select name,age from stafftable where age 22
    select * from staff
    table where dept = "IT"
    select * from stafftable where enrolldate like "2013"
  • 查到的信息,打印后,最后面还要显示查到的条数
  • 可创建新员工纪录,以phone做唯一键,staff_id需自增
  • 可删除指定员工信息纪录,输入员工id,即可删除
  • 可修改员工信息,语法如下:
  •   UPDATE staff_table SET dept="Market" WHERE where dept = "IT"

(2)作业完成情况:

  1. 可进行模糊查询,语法至少支持下面3种
  2. 查到的信息,打印后,最后面还要显示查到的条数
  3. 可删除指定员工信息纪录,输入员工id,即可删除
  4. 可创建新员工纪录,以phone做唯一键,staff_id需自增。

(3)编写感想:

  1. 编写的时候一直想不通这到底怎么写,但后来看到re这个正则模块时候发现可以通过re.split()这个函数变成列表进行处理。
  2. 用字典匹配运算函数。
     1 def computing_dictionary(args):
     2     computing = {
     3         <: greater,
     4         >: less,
     5         =: amount,
     6         like: like,
     7     }
     8 def greater(args,args_1):
     9     date = open_file()
    10     key = db[args]
    11     number = 0
    12     for item in date:
    13         select_date = re.split(",", item)
    14         if select_date[key] < args_1 :
    15             print(item)
    16             number += 1
    17     print("共查询到%s条" %(number))
    18 
    19 def less(args,args_1):
    20     date = open_file()
    21     key = db[args]
    22     print(key)
    23     number = 0
    24     for item in date:
    25         select_date = re.split(",", item)
    26         print(select_date)
    27         if select_date[key] > args_1 :
    28             print(item)
    29             number += 1
    30     print("共查询到%s条" %(number))
    31 def amount(args,args_1):
    32     date = open_file()
    33     key = db[args]
    34     number = 0
    35     print(args_1)
    36     for item in date:
    37         # if  len(item)< 2 :
    38             # continue
    39         select_date = re.split(",", item)
    40         print(select(key))
    41         if select_date[key] == args_1 :
    42             print(item)
    43             number += 1
    44     print("共查询到%s条" % (number))
    45 def like(args,args_1):
    46     date = open_file()
    47     key = db[args]
    48     number = 0
    49     for item in date:
    50         select_date = re.split(",", item)
    51         if select_date[key].find(args_1) >= 0:
    52             print(item)
    53             number += 1
    54     print("共查询到%s条" %number)
  3. update这个功能实在是没有思路。后续如果可以最好能有相关代码查看。

python

标签:功能   匹配   代码   查看   amount   code   ict   gre   log   

原文地址:http://www.cnblogs.com/diyusishen/p/6291226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!