[Zope-Checkins] Re: [Checkins] SVN: Products.Five/trunk/ Now you can use the old registry with the new API for registerig components.

2006-07-28 Thread Florent Guillaume

On 27 Jul 2006, at 16:15, Lennart Regebro wrote:

Modified: Products.Five/trunk/site/localsite.py
===
--- Products.Five/trunk/site/localsite.py	2006-07-27 13:51:25 UTC  
(rev 69270)
+++ Products.Five/trunk/site/localsite.py	2006-07-27 14:15:46 UTC  
(rev 69271)

@@ -16,12 +16,26 @@
 $Id$
 

+from operator import xor
+def one_of_three(a, b, c):
+# Logical table for a three part test where only one can be true:
+# 0 0 0: 0
+# 0 0 1: 1
+# 0 1 0: 1
+# 0 1 1: 0
+# 1 0 0: 1
+# 1 0 1: 0
+# 1 1 0: 0
+# 1 1 1: 0
+return xor(xor(a, b), c) and not (a and b and c)


Heh, boolean algebra is nice but sometimes integers convey the  
meaning much better:

  return int(a)+int(b)+int(c) == 1

Florent

--
Florent Guillaume, Nuxeo (Paris, France)   Director of RD
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]



___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins


[Zope-Checkins] Re: [Checkins] SVN: Products.Five/trunk/ Now you can use the old registry with the new API for registerig components.

2006-07-28 Thread Benji York

Florent Guillaume wrote:

On 27 Jul 2006, at 16:15, Lennart Regebro wrote:


Modified: Products.Five/trunk/site/localsite.py
===
--- Products.Five/trunk/site/localsite.py	2006-07-27 13:51:25 UTC  
(rev 69270)
+++ Products.Five/trunk/site/localsite.py	2006-07-27 14:15:46 UTC  
(rev 69271)

@@ -16,12 +16,26 @@
$Id$


+from operator import xor
+def one_of_three(a, b, c):
+# Logical table for a three part test where only one can be true:
+# 0 0 0: 0
+# 0 0 1: 1
+# 0 1 0: 1
+# 0 1 1: 0
+# 1 0 0: 1
+# 1 0 1: 0
+# 1 1 0: 0
+# 1 1 1: 0
+return xor(xor(a, b), c) and not (a and b and c)



Heh, boolean algebra is nice but sometimes integers convey the  
meaning much better:

   return int(a)+int(b)+int(c) == 1


Hey, this is fun!  How about this:

def only_one(*args):
return sum(bool(i) for i in args) == 1
--
Benji York
Senior Software Engineer
Zope Corporation
___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins


[Zope-Checkins] Re: [Checkins] SVN: Products.Five/trunk/ Now you can use the old registry with the new API for registerig components.

2006-07-28 Thread Florent Guillaume

Indeed :)


On 29 Jul 2006, at 00:39, Benji York wrote:


Florent Guillaume wrote:

On 27 Jul 2006, at 16:15, Lennart Regebro wrote:

Modified: Products.Five/trunk/site/localsite.py
===
--- Products.Five/trunk/site/localsite.py	2006-07-27 13:51:25  
UTC  (rev 69270)
+++ Products.Five/trunk/site/localsite.py	2006-07-27 14:15:46  
UTC  (rev 69271)

@@ -16,12 +16,26 @@
$Id$


+from operator import xor
+def one_of_three(a, b, c):
+# Logical table for a three part test where only one can be  
true:

+# 0 0 0: 0
+# 0 0 1: 1
+# 0 1 0: 1
+# 0 1 1: 0
+# 1 0 0: 1
+# 1 0 1: 0
+# 1 1 0: 0
+# 1 1 1: 0
+return xor(xor(a, b), c) and not (a and b and c)
Heh, boolean algebra is nice but sometimes integers convey the   
meaning much better:

   return int(a)+int(b)+int(c) == 1


Hey, this is fun!  How about this:

def only_one(*args):
return sum(bool(i) for i in args) == 1
--
Benji York
Senior Software Engineer
Zope Corporation


--
Florent Guillaume, Nuxeo (Paris, France)   Director of RD
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]



___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins