December 9th, 2004, 04:31 AM
I need "nor", "nand" expression
Is there a way to get a nor (not or) expressoin that works in eval()?
I would like eval() to handle for example this string "1 nor 0".
December 9th, 2004, 05:27 AM
not (1 or 0)
not (1 and 0)
December 9th, 2004, 05:35 AM
Thanks, but is it possible to make my own "nor" without to much work. That works in eval()? And that is used like "1 nor 0"?
December 9th, 2004, 01:35 PM
No; Python does not allow you to define new operators. While you can define a function nor(), it would have the same syntax and semantics as a normal function.
Originally Posted by southstar
Note that since Python (like most languages) evaluates function arguments eagerly, the clauses would be evaluated before the values are passed to the function, which means that any side-effects that the second clause would have would be take place regardless of the success or failure of the first clause.
def nor(p, q):
return not (p or q);
This can be seen as an argument in favor of adding a macro sublanguage to Python, I suppose, though one that would allow operators would probably be more complex than it would be worth.
December 10th, 2004, 02:37 AM