[melbourne-pug] mapping strings to class
lemeia
lemeia at bigpond.com
Sun Jan 8 11:39:42 CET 2006
Hi all,
I've got so far as to dynamically generate a string of conditions from a configuration file. However, I've run into a few problems.
I've contained the whole set of conditions in one string variable which I then execute using the exec statement.
My string will be similar to this:
if conditionA:
statement1
statement2
return True
elif conditionB:
statement1
statement2
return True
else:
return False
First of all, I found out that I can't use "return" as part of an exec statement unless it is part of a funtion.
So I defined the whole thing as a function (check()) and then called the function from outside of the exec statement.
It sort of looks like this:
def checkResults(self, criteria):
exec(criteria)
return criteria()
But it's all falling appart by now. I don't know how the function should be defined within the exec statement so that I can call it successfully from outside of the exec statement.
The fact is that checkResults() is an attribute of an object when it is being called. So that means I would need to make sure that when my dynamically generated function check() is called it needs to have access to the same object - the comparisons are based on attributes of this object. So how do I do this?
Regards
Patrick
More information about the melbourne-pug
mailing list