December 9th, 2004, 02:35 PM
Originally Posted by southstar
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"?
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.
def nor(p, q):
return not (p or q);
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.
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.