Use dictionary comprehension in selection
When doing a selection, a new context (in the form of a dictionary) is created. Instead of re-using the same dictionary re-assigning the values, now use a comprehension to avoid redundant reads.
This commit is contained in:
parent
bcc7053892
commit
95e375f44a
@ -106,13 +106,11 @@ class relation (object):
|
|||||||
def selection(self, expr):
|
def selection(self, expr):
|
||||||
'''Selection, expr must be a valid boolean expression, can contain field names,
|
'''Selection, expr must be a valid boolean expression, can contain field names,
|
||||||
constant, math operations and boolean ones.'''
|
constant, math operations and boolean ones.'''
|
||||||
attributes = {}
|
|
||||||
newt = relation()
|
newt = relation()
|
||||||
newt.header = header(self.header)
|
newt.header = header(self.header)
|
||||||
for i in self.content:
|
for i in self.content:
|
||||||
# Fills the attributes dictionary with the values of the tuple
|
# Fills the attributes dictionary with the values of the tuple
|
||||||
for j,attr in enumerate(self.header):
|
attributes = {attr:i[j].autocast() for j, attr in enumerate(self.header)}
|
||||||
attributes[attr] = i[j].autocast()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if eval(expr, attributes):
|
if eval(expr, attributes):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user