Hi Saizan,

I don't really see anything wrong with creating a custom class for
evaluating those kinds of logical statements. It does make the code for
statements more concise and easy to follow (with less binding
ambiguity). Mabye something like this would help:

class logic(int):
  def __sub__(self):
    return logic(not self)
  def eval(self, statement):
    return bool(statement)
  def make_logical(self, *args):
    out = []
    for arg in args:
      out.append(logic(arg))
    return out

l = logic()
# init a buch of variables (or a list) at once
x, y, z = l.make_logical(True, False, True)
# or one at a time
v = logic(False)
# evaluate a statement
print l.eval((x and y) or (-z or -v)) # True

Regards,
Jordan

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to