[Assorted-commits] SF.net SVN: assorted: [705] python-commons/trunk/src/commons/misc.py
Brought to you by:
yangzhang
|
From: <yan...@us...> - 2008-05-08 03:18:40
|
Revision: 705
http://assorted.svn.sourceforge.net/assorted/?rev=705&view=rev
Author: yangzhang
Date: 2008-05-07 20:18:47 -0700 (Wed, 07 May 2008)
Log Message:
-----------
added seq, default_if_none
Modified Paths:
--------------
python-commons/trunk/src/commons/misc.py
Modified: python-commons/trunk/src/commons/misc.py
===================================================================
--- python-commons/trunk/src/commons/misc.py 2008-05-07 16:06:28 UTC (rev 704)
+++ python-commons/trunk/src/commons/misc.py 2008-05-08 03:18:47 UTC (rev 705)
@@ -46,3 +46,17 @@
finally:
end = time()
output[0] = end - start
+
+def default_if_none(x, d):
+ """
+ Returns L{x} if it's not None, otherwise returns L{d}.
+ """
+ if x is None: return d
+ else: return x
+
+def seq(f, g):
+ """
+ Evaluate 0-ary functions L{f} then L{g}, returning L{g()}.
+ """
+ f()
+ return g()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|