Commits

Jed Brown committed d728e32 Merge

Merge branch 'jed/python3-binaryio' into maint

* jed/python3-binaryio:
bin/pythonscripts: fix string type checking for Python-3
bin/pythonscripts: updated petsc_conf.py and PetscBinaryIO.py to be compatible with Python 3

Comments (0)

Files changed (2)

bin/pythonscripts/PetscBinaryIO.py

 """
 
 import numpy as np
-import types
 import functools
 
+try:
+    basestring                  # Python-2 has basestring as a common parent of unicode and str
+except NameError:
+    basestring = str            # Python-3 is unicode through and through
+
 def update_wrapper_with_doc(wrapper, wrapped):
     """Similar to functools.update_wrapper, but also gets the wrapper's __doc__ string"""
     wdoc = wrapper.__doc__
 
         if self.precision == 'longlong':
             nbyte = 16
-            print nbyte
         elif self.precision == 'single':
             nbyte = 4
         else:
 
         close = False
 
-        if type(fid) is types.StringType:
+        if isinstance(fid, basestring):
             fid = open(fid, 'rb')
             close = True
 
                     which must be of type Vec, IS, MatSparse, or MatSciPy.
         """
         close = False
-        if type(fid) is types.StringType:
+        if isinstance(fid, basestring):
             fid = open(fid, 'wb')
             close = True
 

bin/pythonscripts/petsc_conf.py

     petscconfinclude = os.path.join(petscdir, 'include', 'petscconf.h')
 
     try:
-        fid = file(petscvariables, 'r')
+        fid = open(petscvariables, 'r')
     except IOError:
         warnings.warn('Nonexistent or invalid PETSc installation, using defaults')
         return None, None, None
         fid.close()
 
     try:
-        fid = file(petscconfinclude, 'r')
+        fid = open(petscconfinclude, 'r')
     except IOError:
         warnings.warn('Nonexistent or invalid PETSc installation, using defaults')
         return None, None, None