码迷,mamicode.com
首页 > 其他好文 > 详细

eval实现字符串化前的功能实现,有效叠加相同代码

时间:2018-11-24 14:09:20      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:print   col   class   orm   where   val   ike   代码   split   

def show(con,col_l,symbol,condition):
    con_name, con_value = con.split(symbol)  # con_name = ‘age‘,con_value = 20
    for line_lst in read_file():
        num = name_value[con_name]  # num = 2
        if eval(condition):
            for col in col_l:  # [‘name‘,‘age‘]
                print(line_lst[name_value[col]], end=‘ ‘)
            print()

def select(sql):
    # sql = ‘select name,age where age>20‘
    col_l, con = format_sql(sql)   # col_l = [‘name‘, ‘age‘],con = age>20
    if ‘>‘ in con:
        show(con,col_l,‘>‘,‘int(con_value) < int(line_lst[num])‘)
    if ‘<‘ in con:
        show(con, col_l, ‘<‘, ‘int(con_value) > int(line_lst[num])‘)
    if ‘=‘ in con:
        show(con, col_l, ‘=‘, ‘con_value == line_lst[num]‘)
    if ‘like‘ in con:
        show(con, col_l, ‘like‘, ‘con_value in line_lst[num]‘)

 

eval实现字符串化前的功能实现,有效叠加相同代码

标签:print   col   class   orm   where   val   ike   代码   split   

原文地址:https://www.cnblogs.com/zhangzhaohua/p/10011455.html

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