Python database applet

Source: 

# dict1 a dictionary, corresponding to the corresponding subscript elements, we will turn into a list of files, i.e. the corresponding index file, the index to find a file element by

dict1 = { 'Sort': 0, ' name ': . 1, ' Age ': 2, ' Phone ': . 3, ' Job ': . 4}

# information is the last to be printed converted into a list of
DEF p_Message (M1):
IF ' * ' in M1:
M1 = dict1.keys ()
return M1
M1 = m1.split ( ',')
for I in Range ( len (M1)):
M1 [I] M1 = [I] .strip ()
return M1


# traverse the file information, it converted into the form of a list
# will be converted into a function generator, the benefits are not all incoming information once the file memory, but by how much mass
DEF op_file (M2):
M2 = m2.strip ()
with Open (M2,encoding='utf=8')as f:
for line in f:
line = line.strip()
line = line.split(',')
yield line

#进行条件筛选
def choose(pp1 ,m3):
lis = []
m3 = m3.strip()
if '>' in m3:
c1 ,c2 = m3.split('>')
c1 = c1.strip()
c2 = c2.strip()
g = op_file(m2)
for line_lis in g:
if int(line_lis[dict1[c1]]) > int(c2):
li = []
for l_list in pp1:
li.append(line_lis[dict1[l_list]])
lis.append(li)
for i in lis:
print(i)
if '<' in m3:
c1,c2 = m3.split('<')
c1 = c1.strip()
c2 = c2.strip()
g = op_file(m2)
for line_lis in g:
if int(line_lis[dict1[c1]]) < int(c2):
li = []
for l_list in pp1:
li.append(line_lis[dict1[l_list]])
lis.append(li)
for i in lis:
print(i)
if '=' in m3:
c1, c2 = m3.split('=')
c1 = c1.strip()
c2 = c2.strip()
g = op_file(m2)
for line_lis in g:
if c2 in line_lis[dict1[c1]]:
li = []
for l_list in pp1:
li.append(line_lis[dict1[l_list]])
lis.append(li)
I for in LIS:
Print (I)



# condition input information analyzing
the while . 1:
Message = INPUT ( '>>>')
# Message = 'SELECT name, info from WHERE Age Age> 22 is'
# M1: We want to print the final information m2: filename m3: filters
M1, M3 = message.split ( 'the WHERE')
M1, M2 = m1.split ( 'from')
M1 = m1.replace ( 'the SELECT', '') .strip ( )

# PP1 is finished modifying M1
PP1 = p_Message (M1)
op_file (M2)
the Choose (PP1, M3)



contents of the file:
1,Alex,22,13651054608,IT
2,Egon,23,13304320533,Tearcher
3,nezha,25,1333235322,IT
 

Guess you like

Origin www.cnblogs.com/if-it-is-possible/p/11519636.html