forked from DataStories-UniPi/miniDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.py
More file actions
29 lines (25 loc) · 805 Bytes
/
misc.py
File metadata and controls
29 lines (25 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import operator
def get_op(op, a, b):
'''
Get op as a function of a and b by using a symbol
'''
ops = {'>': operator.gt,
'<': operator.lt,
'>=': operator.ge,
'<=': operator.le,
'==': operator.eq}
try:
return ops[op](a,b)
except TypeError: # if a or b is None (deleted record), python3 raises typerror
return False
def split_condition(condition):
condition = condition.replace(' ','') # remove all whitespaces
ops = {'>=': operator.ge,
'<=': operator.le,
'==': operator.eq,
'>': operator.gt,
'<': operator.lt}
for op_key in ops.keys():
splt=condition.split(op_key)
if len(splt)>1:
return splt[0], op_key, splt[1]