员工信息表作业

'''
select name, age where age>22
select * where job=IT
select * where phone like 133
1,Alex,22,13651054608,IT
2,Egon,23,13304320533,Tearcher
3,nezha,25,1333235322,IT

'''

dic={'id':0,'name':1,'age':2,'phone':3,'job':4}

def show_func(show,lst):
if '*' in show:
print(lst)
else:
for i in show:
print(lst[dic[i.strip()]],' ',end='')
print()

def filter(key):
show,condition=key.strip().split('where')
show=show.replace('select','')
show=show.strip().split(',')
return show,condition

def add_new():
pass

key=input('select name where age=23')
show,condition=filter(key)

with open('file',encoding='utf-8')as f:
for line in f:
lst=line.strip().split(',')
'''做符号判断'''
if '>' in condition:
a,b=condition.strip().split('>')
if lst[dic[a]]>b:
show_func(show,lst)
if '<' in condition:
a,b=condition.strip().split('<')
if lst[dic[a]]<b:
show_func(show,lst)
if '=' in condition:
a,b=condition.strip().split('=')
if lst[dic[a]]==b:
show_func(show,lst)
if 'like' in condition:
a,b=condition.strip().split('like')
a,b=a.strip(),b.strip()
if b in lst[dic[a]]:
show_func(show,lst)
posted @ 2020-03-25 08:09  新手战斗机  阅读(151)  评论(0编辑  收藏  举报