[Scipy-svn] r4089 - trunk/scipy/io/arff

scipy-svn@scip... scipy-svn@scip...
Mon Apr 7 13:07:57 CDT 2008


Author: cdavid
Date: 2008-04-07 13:07:49 -0500 (Mon, 07 Apr 2008)
New Revision: 4089

Added:
   trunk/scipy/io/arff/myfunctools.py
   trunk/scipy/io/arff/utils.py
Log:
Add implementation for functool.partial for python < 2.5

Added: trunk/scipy/io/arff/myfunctools.py
===================================================================
--- trunk/scipy/io/arff/myfunctools.py	2008-04-07 18:05:47 UTC (rev 4088)
+++ trunk/scipy/io/arff/myfunctools.py	2008-04-07 18:07:49 UTC (rev 4089)
@@ -0,0 +1,18 @@
+# Last Change: Mon Aug 20 01:00 PM 2007 J
+# Implement partial application (should only be used if functools is not
+# available (eg python < 2.5)
+
+class partial:
+    def __init__(self, fun, *args, **kwargs):
+        self.fun = fun
+        self.pending = args[:]
+        self.kwargs = kwargs.copy()
+
+    def __call__(self, *args, **kwargs):
+        if kwargs and self.kwargs:
+            kw = self.kwargs.copy()
+            kw.update(kwargs)
+        else:
+            kw = kwargs or self.kwargs
+
+        return self.fun(*(self.pending + args), **kw)

Added: trunk/scipy/io/arff/utils.py
===================================================================
--- trunk/scipy/io/arff/utils.py	2008-04-07 18:05:47 UTC (rev 4088)
+++ trunk/scipy/io/arff/utils.py	2008-04-07 18:07:49 UTC (rev 4089)
@@ -0,0 +1,7 @@
+#! /usr/bin/env python
+# Last Change: Mon Aug 20 02:00 PM 2007 J
+
+try:
+    from functools import partial
+except ImportError:
+    from myfunctools import partial



More information about the Scipy-svn mailing list