[Scipy-svn] r2480 - trunk/Lib/io

scipy-svn at scipy.org scipy-svn at scipy.org
Wed Jan 3 00:08:27 CST 2007


Author: timl
Date: 2007-01-03 00:08:11 -0600 (Wed, 03 Jan 2007)
New Revision: 2480

Modified:
   trunk/Lib/io/array_import.py
Log:
apply patch from #274

Modified: trunk/Lib/io/array_import.py
===================================================================
--- trunk/Lib/io/array_import.py	2007-01-03 04:20:22 UTC (rev 2479)
+++ trunk/Lib/io/array_import.py	2007-01-03 06:08:11 UTC (rev 2480)
@@ -90,8 +90,12 @@
     return linelist
 
 def get_open_file(fileobject, mode='rb'):
-    if isinstance(fileobject, types.StringType):
+    try:
+        # this is the duck typing check: if fileobject
+        # can be used is os.path.expanduser, it is a string
+        # otherwise it is a fileobject
         fileobject = os.path.expanduser(fileobject)
+
         if mode[0]=='r' and not os.path.exists(fileobject):
             raise IOError, (2, 'No such file or directory: '
                             + fileobject)
@@ -103,7 +107,9 @@
                 if type(details) == type(()):
                     details = details + (fileobject,)
                 raise IOError, details
-    else:
+    except AttributeError:
+        # it is assumed that the fileobject is a python
+        # file object if it can not be used in os.path.expanduser
         file = fileobject
 
     return file



More information about the Scipy-svn mailing list