getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] (no subject)


From: Yves Renard
Subject: [Getfem-commits] (no subject)
Date: Thu, 29 Jun 2017 05:25:53 -0400 (EDT)

branch: devel-yves
commit 206462f51d8201056183b9fba090c014aed0f50c
Author: Yves Renard <address@hidden>
Date:   Thu Jun 29 11:24:09 2017 +0200

    Ensure compatibility of the python interface to python 3.x, 
--enable-python3 of the configure script enable the interface with python 3.x
---
 bin/extract_doc                                    | 498 ++++++++++-----------
 bin/rst_to_xml.py                                  |  18 +-
 configure.ac                                       |  41 +-
 contrib/test_plasticity/Makefile.am                |   2 +-
 contrib/test_plasticity/test_plasticity.py         |   8 +-
 doc/sphinx/source/install/install_linux.rst        |   8 +
 doc/sphinx/source/install/install_mac.rst          |   8 +-
 doc/sphinx/source/install/install_windows.rst      |  13 +-
 doc/sphinx/source/userdoc/gasm_high.rst            |   4 +-
 interface/src/gf_mesh_fem_get.cc                   |   8 +-
 interface/src/python/Makefile.am                   |   7 +-
 interface/src/python/getfem_python.c               |  77 +++-
 interface/tests/python/Makefile.am                 |   2 +-
 interface/tests/python/check_export.py             |   2 +-
 interface/tests/python/check_levelset.py           |   2 +-
 interface/tests/python/demo_crack.py               |   6 +-
 interface/tests/python/demo_fictitious_domains.py  |  12 +-
 interface/tests/python/demo_laplacian.py           |  10 +-
 interface/tests/python/demo_laplacian_DG.py        |  14 +-
 .../tests/python/demo_laplacian_aposteriori.py     | 102 ++---
 interface/tests/python/demo_laplacian_pyramid.py   |  18 +-
 interface/tests/python/demo_navier_stokes.py       |   5 +-
 .../tests/python/demo_nonlinear_elasticity.py      |   4 +-
 interface/tests/python/demo_parallel_laplacian.py  |  34 +-
 interface/tests/python/demo_plasticity.py          |   8 +-
 interface/tests/python/demo_plate.py               |  14 +-
 interface/tests/python/demo_static_contact.py      |  12 +-
 interface/tests/python/demo_step_by_step.py        |   4 +-
 interface/tests/python/demo_stokes_3D_tank.py      |  14 +-
 interface/tests/python/demo_stokes_3D_tank_draw.py |   8 +-
 .../demo_thermo_elasticity_electrical_coupling.py  |  20 +-
 interface/tests/python/demo_tripod.py              |  26 +-
 interface/tests/python/demo_tripod_alt.py          |  24 +-
 interface/tests/python/demo_wave.py                |   8 +-
 interface/tests/python/demo_wheel_contact.py       |  16 +-
 interface/tests/python/getfem_tvtk.py              |  14 +-
 m4/ac_python_devel.m4                              |  27 +-
 37 files changed, 590 insertions(+), 508 deletions(-)

diff --git a/bin/extract_doc b/bin/extract_doc
index 0dedb3e..047a24d 100755
--- a/bin/extract_doc
+++ b/bin/extract_doc
@@ -466,7 +466,7 @@ option = sys.argv[2]
 # List the filenames and extract object and command names.
 #
 
-fl = os.popen('sh -c "(cd ' + directory + ' ; ls gf_*.cc)"');
+fl = os.popen('(cd ' + directory + ' ; ls gf_*.cc)');
 lines = fl.readlines();
 fl.close()
 objects = set()
@@ -848,67 +848,67 @@ elif (option == 'matlab-doc'):
 
   langage = 'matlab'
   
-  print '.. Automatically generated file, do not edit it.'
-  print '.. If some modification are necessary, please modify'
-  print '.. the corresponding C++ source or the python program extract_doc'
-  print ''
-  print ''
-  print '.. include:: ../replaces.txt'
-  print ''
-  print '.. highlightlang:: matlab'
-  print ''
-  print '.. _mlab-cmdref:'
-  print ''
-  print 'Command reference'
-  print '================='
-  print ''
-  print 'Please remember that this documentation is not self contained.'
-  print 'You should in particular refer to the `user documentation`_ '
-  print 'to have a more extensive description of the structures algorithms '
-  print 'and concepts used.'
-  print ''
-  # print 'Types'
-  # print '-----'
-  print ''
-  print 'The expected type of each function argument is indicated in this '
-  print 'reference. Here is a list of these types:'
-  print ''
-  print '=====================  
=================================================='
-  print '`int`                  integer value'
-  print '`hobj`                 a handle for any GetFEM++ object'
-  print '`scalar`               scalar value'
-  print '`string`               string'
-  print '`ivec`                 vector of integer values'
-  print '`vec`                  vector'
-  print '`imat`                 matrix of integer values'
-  print '`mat`                  matrix'
-  print '`spmat`                sparse matrix (both matlab native sparse'
-  print '                       matrices, and GetFEM sparse matrices)'
-  print '`precond`              GetFEM preconditioner object'
-  print '`mesh mesh`            object descriptor (or gfMesh object)'
-  print '`mesh_fem`             mesh fem object descriptor (or gfMeshFem 
object)'
-  print '`mesh_im`              mesh im object descriptor (or gfMeshIm object)'
-  print '`mesh_im_data`         mesh im data object descriptor (or 
gfMeshImData object)'
-  print '`mesh_slice`           mesh slice object descriptor (or gfSlice 
object)'
-  print '`cvstruct`             convex structure descriptor (or gfCvStruct 
object)'
-  print '`geotrans`             geometric transformation descriptor (or '
-  print '                       gfGeoTrans object)'
-  print '`fem`                  fem descriptor (or gfFem object)'
-  print '`eltm`                 elementary matrix descriptor (or gfEltm 
object)'
-  print '`integ`                integration method descriptor (or gfInteg 
object)'
-  print '`model`                model descriptor (or gfModel object)'
-  print '`global_function`      global function descriptor'
-  print '`mesher_object`        mesher object descriptor'
-  print '`cont_struct`          continuation-structure descriptor'
-  print '=====================  
=================================================='
-  print ''  
-  print 'Arguments listed between square brackets are optional. Lists between 
braces indicate that the argument must match one of the elements of the list. 
For example::'
-  print ''
-  print '  >> [X,Y]=dummy(int i, \'foo\' | \'bar\' [,vec v])'
-  print ''
-  print 'means that the dummy function takes two or three arguments, its first 
being an integer value, the second a string which is either \'foo\' or \'bar\', 
and a third optional argument. It returns two values (with the usual matlab 
meaning, i.e. the caller can always choose to ignore them).'
-  print ''
-  print ''
+  print('.. Automatically generated file, do not edit it.')
+  print('.. If some modification are necessary, please modify')
+  print('.. the corresponding C++ source or the python program extract_doc')
+  print('')
+  print('')
+  print('.. include:: ../replaces.txt')
+  print('')
+  print('.. highlightlang:: matlab')
+  print('')
+  print('.. _mlab-cmdref:')
+  print('')
+  print('Command reference')
+  print('=================')
+  print('')
+  print('Please remember that this documentation is not self contained.')
+  print('You should in particular refer to the `user documentation`_ ')
+  print('to have a more extensive description of the structures algorithms ')
+  print('and concepts used.')
+  print('')
+  # print('Types')
+  # print('-----')
+  print('')
+  print('The expected type of each function argument is indicated in this ')
+  print('reference. Here is a list of these types:')
+  print('')
+  print('=====================  
==================================================')
+  print('`int`                  integer value')
+  print('`hobj`                 a handle for any GetFEM++ object')
+  print('`scalar`               scalar value')
+  print('`string`               string')
+  print('`ivec`                 vector of integer values')
+  print('`vec`                  vector')
+  print('`imat`                 matrix of integer values')
+  print('`mat`                  matrix')
+  print('`spmat`                sparse matrix (both matlab native sparse')
+  print('                       matrices, and GetFEM sparse matrices)')
+  print('`precond`              GetFEM preconditioner object')
+  print('`mesh mesh`            object descriptor (or gfMesh object)')
+  print('`mesh_fem`             mesh fem object descriptor (or gfMeshFem 
object)')
+  print('`mesh_im`              mesh im object descriptor (or gfMeshIm 
object)')
+  print('`mesh_im_data`         mesh im data object descriptor (or 
gfMeshImData object)')
+  print('`mesh_slice`           mesh slice object descriptor (or gfSlice 
object)')
+  print('`cvstruct`             convex structure descriptor (or gfCvStruct 
object)')
+  print('`geotrans`             geometric transformation descriptor (or ')
+  print('                       gfGeoTrans object)')
+  print('`fem`                  fem descriptor (or gfFem object)')
+  print('`eltm`                 elementary matrix descriptor (or gfEltm 
object)')
+  print('`integ`                integration method descriptor (or gfInteg 
object)')
+  print('`model`                model descriptor (or gfModel object)')
+  print('`global_function`      global function descriptor')
+  print('`mesher_object`        mesher object descriptor')
+  print('`cont_struct`          continuation-structure descriptor')
+  print('=====================  
==================================================')
+  print('') 
+  print('Arguments listed between square brackets are optional. Lists between 
braces indicate that the argument must match one of the elements of the list. 
For example::')
+  print('')
+  print('  >> [X,Y]=dummy(int i, \'foo\' | \'bar\' [,vec v])')
+  print('')
+  print('means that the dummy function takes two or three arguments, its first 
being an integer value, the second a string which is either \'foo\' or \'bar\', 
and a third optional argument. It returns two values (with the usual matlab 
meaning, i.e. the caller can always choose to ignore them).')
+  print('')
+  print('')
   allc = sorted(objects+commands)
   for o in allc:
     for ext in ['', '_get', '_set']:
@@ -916,13 +916,13 @@ elif (option == 'matlab-doc'):
       [r, initiale] = StandardObjectName(o)
       if (os.path.exists(src_dir) and os.path.isfile(src_dir)):
         
-        print 'gf_' + o + ext
-        print '-------------------------------------------'
-        print ''
-        print '**Synopsis**'
-        print ''
-        print '::'
-        print ''
+        print('gf_' + o + ext)
+        print('-------------------------------------------')
+        print('')
+        print('**Synopsis**')
+        print('')
+        print('::')
+        print('')
         [gdoc, args] = ExtractGlobalDoc(src_dir);
         if (args != ''):
           args = FilterDoc(args, langage, objects, commands) + ', '
@@ -947,18 +947,18 @@ elif (option == 'matlab-doc'):
           [ok, doc, dtype, mname, params, ret] = ExtractSubDoc(fl, langage)
 
         fl.close()
-        print ''
-        print '**Description :**'
-        print ''
-        print ''
+        print('')
+        print('**Description :**')
+        print('')
+        print('')
         if ((o in set_objects) and (ext == '')):
           print 'General constructor for ' + o + ' objects.\n'
         gdoc = FilterDoc(gdoc, langage, objects, commands)
-        print gdoc
-        print ''
-        print '**Command list :**'
-        print ''
-        print ''
+        print(gdoc)
+        print('')
+        print('**Command list :**')
+        print('')
+        print('')
         fl = open(src_dir)
         doc = '';
         [ok, doc, dtype, mname, params, ret] = ExtractSubDoc(fl, langage)
@@ -972,9 +972,9 @@ elif (option == 'matlab-doc'):
           else:
             mname = ''
             params = params[1:].strip()
-          print ''
+          print('')
           print('  ``' + ret + 'gf_'+o+ext+firstarg+mname + params+')``')
-          print ''
+          print('')
           doc = FilterDoc(doc, langage, objects, commands)
           nbspace = -1; util_pos = -1; nbsp = -1
           for l in doc.split('\n'):
@@ -1002,12 +1002,12 @@ elif (option == 'matlab-doc'):
               
             if (nbsp > nbspace):
                 for i in range (nbsp-nbspace):
-                    print '',
+                    print(''),
             
             if (nbspace >= 0):
                 print('    '+l)
                 
-          print ''
+          print('')
           [ok, doc, dtype, mname, params, ret] = ExtractSubDoc(fl, langage)
     
         fl.close()
@@ -1370,67 +1370,67 @@ elif (option == 'scilab-doc-rst'):
 
   langage = 'scilab'
   
-  print '.. Automatically generated file, do not edit it.'
-  print '.. If some modification are necessary, please modify'
-  print '.. the corresponding C++ source or the python program extract_doc'
-  print ''
-  print ''
-  print '.. include:: ../replaces.txt'
-  print ''
-  print '.. highlightlang:: matlab'
-  print ''
-  print '.. _scilab-cmdref:'
-  print ''
-  print 'Command reference'
-  print '================='
-  print ''
-  print 'Please remember that this documentation is not self contained.'
-  print 'You should in particular refer to the `user documentation`_ '
-  print 'to have a more extensive description of the structures algorithms '
-  print 'and concepts used.'
-  print ''
-  # print 'Types'
-  # print '-----'
-  print ''
-  print 'The expected type of each function argument is indicated in this '
-  print 'reference. Here is a list of these types:'
-  print ''
-  print '=====================  
=================================================='
-  print '`int`                  integer value'
-  print '`hobj`                 a handle for any GetFEM++ object'
-  print '`scalar`               scalar value'
-  print '`string`               string'
-  print '`ivec`                 vector of integer values'
-  print '`vec`                  vector'
-  print '`imat`                 matrix of integer values'
-  print '`mat`                  matrix'
-  print '`spmat`                sparse matrix (both matlab native sparse'
-  print '                       matrices, and GetFEM sparse matrices)'
-  print '`precond`              GetFEM preconditioner object'
-  print '`mesh mesh`            object descriptor (or gfMesh object)'
-  print '`mesh_fem`             mesh fem object descriptor (or gfMeshFem 
object)'
-  print '`mesh_im`              mesh im object descriptor (or gfMeshIm object)'
-  print '`mesh_im_data`         mesh im data object descriptor (or 
gfMeshImData object)'
-  print '`mesh_slice`           mesh slice object descriptor (or gfSlice 
object)'
-  print '`cvstruct`             convex structure descriptor (or gfCvStruct 
object)'
-  print '`geotrans`             geometric transformation descriptor (or '
-  print '                       gfGeoTrans object)'
-  print '`fem`                  fem descriptor (or gfFem object)'
-  print '`eltm`                 elementary matrix descriptor (or gfEltm 
object)'
-  print '`integ`                integration method descriptor (or gfInteg 
object)'
-  print '`model`                model descriptor (or gfModel object)'
-  print '`global_function`      global function descriptor'
-  print '`mesher_object`        mesher object descriptor'
-  print '`cont_struct`          continuation-structure descriptor'
-  print '=====================  
=================================================='
-  print ''  
-  print 'Arguments listed between square brackets are optional. Lists between 
braces indicate that the argument must match one of the elements of the list. 
For example::'
-  print ''
-  print '  >> [X,Y]=dummy(int i, \'foo\' | \'bar\' [,vec v])'
-  print ''
-  print 'means that the dummy function takes two or three arguments, its first 
being an integer value, the second a string which is either \'foo\' or \'bar\', 
and a third optional argument. It returns two values (with the usual matlab 
meaning, i.e. the caller can always choose to ignore them).'
-  print ''
-  print ''
+  print('.. Automatically generated file, do not edit it.')
+  print('.. If some modification are necessary, please modify')
+  print('.. the corresponding C++ source or the python program extract_doc')
+  print('')
+  print('')
+  print('.. include:: ../replaces.txt')
+  print('')
+  print('.. highlightlang:: matlab')
+  print('')
+  print('.. _scilab-cmdref:')
+  print('')
+  print('Command reference')
+  print('=================')
+  print('')
+  print('Please remember that this documentation is not self contained.')
+  print('You should in particular refer to the `user documentation`_ ')
+  print('to have a more extensive description of the structures algorithms ')
+  print('and concepts used.')
+  print('')
+  # print('Types')
+  # print('-----')
+  print('')
+  print('The expected type of each function argument is indicated in this ')
+  print('reference. Here is a list of these types:')
+  print('')
+  print('=====================  
==================================================')
+  print('`int`                  integer value')
+  print('`hobj`                 a handle for any GetFEM++ object')
+  print('`scalar`               scalar value')
+  print('`string`               string')
+  print('`ivec`                 vector of integer values')
+  print('`vec`                  vector')
+  print('`imat`                 matrix of integer values')
+  print('`mat`                  matrix')
+  print('`spmat`                sparse matrix (both matlab native sparse')
+  print('                       matrices, and GetFEM sparse matrices)')
+  print('`precond`              GetFEM preconditioner object')
+  print('`mesh mesh`            object descriptor (or gfMesh object)')
+  print('`mesh_fem`             mesh fem object descriptor (or gfMeshFem 
object)')
+  print('`mesh_im`              mesh im object descriptor (or gfMeshIm 
object)')
+  print('`mesh_im_data`         mesh im data object descriptor (or 
gfMeshImData object)')
+  print('`mesh_slice`           mesh slice object descriptor (or gfSlice 
object)')
+  print('`cvstruct`             convex structure descriptor (or gfCvStruct 
object)')
+  print('`geotrans`             geometric transformation descriptor (or ')
+  print('                       gfGeoTrans object)')
+  print('`fem`                  fem descriptor (or gfFem object)')
+  print('`eltm`                 elementary matrix descriptor (or gfEltm 
object)')
+  print('`integ`                integration method descriptor (or gfInteg 
object)')
+  print('`model`                model descriptor (or gfModel object)')
+  print('`global_function`      global function descriptor')
+  print('`mesher_object`        mesher object descriptor')
+  print('`cont_struct`          continuation-structure descriptor')
+  print('=====================  
==================================================')
+  print('')
+  print('Arguments listed between square brackets are optional. Lists between 
braces indicate that the argument must match one of the elements of the list. 
For example::')
+  print('')
+  print('  >> [X,Y]=dummy(int i, \'foo\' | \'bar\' [,vec v])')
+  print('')
+  print('means that the dummy function takes two or three arguments, its first 
being an integer value, the second a string which is either \'foo\' or \'bar\', 
and a third optional argument. It returns two values (with the usual matlab 
meaning, i.e. the caller can always choose to ignore them).')
+  print('')
+  print('')
   allc = sorted(objects+commands)
   for o in allc:
     for ext in ['', '_get', '_set']:
@@ -1438,13 +1438,13 @@ elif (option == 'scilab-doc-rst'):
       [r, initiale] = StandardObjectName(o)
       if (os.path.exists(src_dir) and os.path.isfile(src_dir)):
         
-        print 'gf_' + o + ext
-        print '-------------------------------------------'
-        print ''
-        print '**Synopsis**'
-        print ''
-        print '::'
-        print ''
+        print('gf_' + o + ext)
+        print('-------------------------------------------')
+        print('')
+        print('**Synopsis**')
+        print('')
+        print('::')
+        print('')
         [gdoc, args] = ExtractGlobalDoc(src_dir);
         if (args != ''):
           args = FilterDoc(args, langage, objects, commands) + ', '
@@ -1469,18 +1469,18 @@ elif (option == 'scilab-doc-rst'):
           [ok, doc, dtype, mname, params, ret] = ExtractSubDoc(fl, langage)
 
         fl.close()
-        print ''
-        print '**Description :**'
-        print ''
-        print ''
+        print('')
+        print('**Description :**')
+        print('')
+        print('')
         if ((o in set_objects) and (ext == '')):
           print 'General constructor for ' + o + ' objects.\n'
         gdoc = FilterDoc(gdoc, langage, objects, commands)
-        print gdoc
-        print ''
-        print '**Command list :**'
-        print ''
-        print ''
+        print(gdoc)
+        print('')
+        print('**Command list :**')
+        print('')
+        print('')
         fl = open(src_dir)
         doc = '';
         [ok, doc, dtype, mname, params, ret] = ExtractSubDoc(fl, langage)
@@ -1494,9 +1494,9 @@ elif (option == 'scilab-doc-rst'):
           else:
             mname = ''
             params = params[1:].strip()
-          print ''
+          print('')
           print('  ``' + ret + 'gf_'+o+ext+firstarg+mname + params+')``')
-          print ''
+          print('')
           doc = FilterDoc(doc, langage, objects, commands)
           nbspace = -1; util_pos = -1; nbsp = -1
           for l in doc.split('\n'):
@@ -1524,12 +1524,12 @@ elif (option == 'scilab-doc-rst'):
               
             if (nbsp > nbspace):
                 for i in range (nbsp-nbspace):
-                    print '',
+                    print (''),
             
             if (nbspace >= 0):
                 print('    '+l)
 
-          print ''
+          print('')
           [ok, doc, dtype, mname, params, ret] = ExtractSubDoc(fl, langage)
     
         fl.close()
@@ -1551,7 +1551,7 @@ elif (option == 'scilab-doc-rst'):
 elif (option == 'python-com' or option == 'python-com-par'):
   langage = 'python'
 
-  print """#!/usr/bin/env python
+  print("""#!/usr/bin/env python
 # -*- coding: iso-8859-1 -*-
 #
 # Python GetFEM++ interface
@@ -1582,14 +1582,14 @@ elif (option == 'python-com' or option == 
'python-com-par'):
 
 import sys
 import numpy
-"""
+""")
   if (option == 'python-com-par'):
-      print "import mpi4py.MPI as mpi"
-      print "getfem_python_par=True"
+      print("import mpi4py.MPI as mpi")
+      print("getfem_python_par=True")
   else:
-      print "getfem_python_par=False"
+      print("getfem_python_par=False")
 
-  print """
+  print("""
 
 try:
   import numbers
@@ -1605,12 +1605,12 @@ getfem('workspace', 'clear all')
 
 def generic_constructor(self, clname, *args):
     \"\"\"Internal function -- acts as a constructor for all GetFEM 
objects.\"\"\"
-    #print 'generic_constructor.'+clname+'('+str(args)+')'
+    #print('generic_constructor.'+clname+'('+str(args)+')')
     if (len(args)==1 and type(args[0]) is GetfemObject):
       if hasattr(self,'id'):
-        print \"warning: hasattr(self,'id')!\"
-        print \"self.id: \",self.id
-        print \"args[0]: \",args[0]
+        print(\"warning: hasattr(self,'id')!\")
+        print(\"self.id: \",self.id)
+        print(\"args[0]: \",args[0])
       else:
         self.id = args[0]
         #if obj_count.get(self.id,0)==0:
@@ -1623,14 +1623,14 @@ def generic_destructor(self, destructible=True):
     \"\"\"Internal function -- acts as a destructor for all GetFEM 
objects.\"\"\"
     if (not hasattr(self,'id')):
       return
-    #print \"Mesh.__del__       \",self.id,'count=',obj_count[self.id]
-    if (obj_count.has_key(self.id)):
+    #print(\"Mesh.__del__       \",self.id,'count=',obj_count[self.id])
+    if (self.id in obj_count):
       obj_count[self.id] = obj_count[self.id]-1
       if (destructible and obj_count[self.id] == 0):
         getfem('delete',self.id)
-        #print \"effective deletion\"
+        #print(\"effective deletion\")
 
-"""
+""")
 
   # one pass to find the set methods having identical name with a get method
   # in that case 'set_' is added to the set method.
@@ -1679,14 +1679,14 @@ def generic_destructor(self, destructible=True):
     firstarg = '(' + args
 
 
-    print '\n#\n# GetFEM class ' + oname + ' definition.\n#\n'
-    print 'class ' + oname + ':'
-    print '  """GetFEM ' + oname + ' object\n'
+    print('\n#\n# GetFEM class ' + oname + ' definition.\n#\n')
+    print('class ' + oname + ':')
+    print('  """GeFEM ' + oname + ' object\n')
     gdoc = FilterDoc(gdoc, langage, objects, commands, set_replace)
-    print gdoc
-    print '  """'
-    print '  def __init__(self, *args):'
-    print '    """General constructor for ' + oname + " objects\n"
+    print(gdoc)
+    print('  """')
+    print('  def __init__(self, *args):')
+    print('    """General constructor for ' + oname + " objects\n")
     # documentation for constructors
     if (os.path.exists(src_dir) and os.path.isfile(src_dir)):
       fl = open(src_dir)
@@ -1729,37 +1729,37 @@ def generic_destructor(self, destructible=True):
 
           if (nbsp > nbspace):
               for i in range (nbsp-nbspace):
-                  print '',
+                  print(''),
 
           if (nbspace >= 0):
               print('    '+l)
               
-        print ''
+        print('')
         [ok, doc, dtype, mname, params, ret] = ExtractSubDoc(fl, langage)
 
       fl.close()
-    print '    """'
-    print '    generic_constructor(self,\'' + o + '\',*args)'
-    print '  def __del__(self):'
+    print('    """')
+    print('    generic_constructor(self,\'' + o + '\',*args)')
+    print('  def __del__(self):')
     if (o in non_destructible_objects):
-      print '    generic_destructor(self, destructible=False)'
+      print('    generic_destructor(self, destructible=False)')
     else:
-      print '    generic_destructor(self, destructible=True)'
+      print('    generic_destructor(self, destructible=True)')
     if (os.path.exists(directory + '/gf_' + o + '_get.cc')):
-      print '  def get(self, *args):'
-      print '    return getfem(\''+o+'_get\',self.id, *args)'
-      print '  def __repr__(self):'
-      print '    getfem(\''+o+'_get\',self.id, \'display\')'
-      print '    return \'\''
+      print('  def get(self, *args):')
+      print('    return getfem(\''+o+'_get\',self.id, *args)')
+      print('  def __repr__(self):')
+      print('    getfem(\''+o+'_get\',self.id, \'display\')')
+      print('    return \'\'')
     if (os.path.exists(directory + '/gf_' + o + '_set.cc')):
-      print '  def set(self, *args):'
-      print '    return getfem(\''+o+'_set\',self.id, *args)'
-    print '  def __str__(self):'
-    print '    return self.char()'
+      print('  def set(self, *args):')
+      print('    return getfem(\''+o+'_set\',self.id, *args)')
+    print('  def __str__(self):')
+    print('    return self.char()')
     if (os.path.exists(src_dir) and os.path.isfile(src_dir)):
       pythonext = ExtractExt(src_dir, langage);
       if (pythonext != ''):
-        print '\n' + pythonext
+        print('\n' + pythonext)
     # add the list of get and set methods
     sub_com = set()
     for ext in ['_get', '_set']:
@@ -1785,7 +1785,7 @@ def generic_destructor(self, destructible=True):
           sub_com.add(mname)
           mparams = FilterDoc(params, langage, objects, commands)
           params = SynopsisToPythonArgs(params)
-          print ''
+          print('')
           sys.stdout.write('  def ')
           mmname = mname
           if (set_extend): mmname = 'set_' + mname
@@ -1834,7 +1834,7 @@ def generic_destructor(self, destructible=True):
               if (nbspace >= 0):
                   sys.stdout.write('    ' + l)
                   
-          print '"""'
+          print('"""')
           sys.stdout.write('    return self.' + ext[1:] + '("' + mname + '"')
           for p in params:
             sys.stdout.write(', ' + p.split('=')[0])
@@ -1844,7 +1844,7 @@ def generic_destructor(self, destructible=True):
         fl.close()
         pythonext = ExtractExt(src_dir, langage);
         if (pythonext != ''):
-          print '\n' + pythonext
+          print('\n' + pythonext)
 
 
 
@@ -1852,7 +1852,7 @@ def generic_destructor(self, destructible=True):
   for c in co:
     src_dir = directory + '/gf_' + c + '.cc'
     if (c != 'workspace' and os.path.exists(src_dir) and 
os.path.isfile(src_dir)):
-      print '#\n# ' + c + ' module\n#\n'
+      print('#\n# ' + c + ' module\n#\n')
       [gdoc, args] = ExtractGlobalDoc(src_dir);
       margs = FilterDoc(args, langage, objects, commands).strip()
       args = SynopsisToPythonArgs(args)
@@ -1864,7 +1864,7 @@ def generic_destructor(self, destructible=True):
         mname = string.replace(mname, '-', '_');
         mparams = FilterDoc(params, langage, objects, commands).strip()
         params = SynopsisToPythonArgs(params)
-        print ''
+        print('')
         if (mname[0] == '.'):
           sys.stdout.write('def ' + c + '(')
         else:
@@ -1924,7 +1924,7 @@ def generic_destructor(self, destructible=True):
             if (nbspace >= 0):
                 sys.stdout.write('  ' + l)
 
-        print '"""'
+        print('"""')
         sys.stdout.write('  return getfem(\'' + c + '\'')
         for p in args:
           sys.stdout.write(', ' + p.split('=')[0])
@@ -1938,30 +1938,30 @@ def generic_destructor(self, destructible=True):
       fl.close()
       pythonext = ExtractExt(src_dir, langage);
       if (pythonext != ''):
-        print '\n' + pythonext
+        print('\n' + pythonext)
 
 
 
 
-  print '\ndef memstats():'
-  print '  print "*** GetFEM view of the workspace:"'
-  print '  getfem(\'workspace\',\'stats\')'
-  print '  print "*** Python view of the workspace:"'
-  print '  for id,c in obj_count.iteritems():'
-  print '    if (c):'
-  print '      name=str(factory(id).__class__)'
-  print '      print "%s class %d, id %d : instances=%d" % 
(name,id.classid,id.objid,c)\n'
+  print('\ndef memstats():')
+  print('  print("*** GetFEM view of the workspace:")')
+  print('  getfem(\'workspace\',\'stats\')')
+  print('  print("*** Python view of the workspace:")')
+  print('  for id,c in obj_count.items():')
+  print('    if (c):')
+  print('      name=str(factory(id).__class__)')
+  print('      print("%s class %d, id %d : instances=%d" % 
(name,id.classid,id.objid,c))\n')
 
-  print 'def linsolve(what, *args):'
-  print '  return getfem(\'linsolve\', what, *args)'
-  print 'def compute(mf, U, what, *args):'
-  print '  return getfem(\'compute\', mf, U, what, *args)'
-  print 'def asm(what, *args):'
-  print '  return getfem(\'asm\', what, *args)'
-  print 'def util(what, *args):'
-  print '  return getfem(\'util\', what, *args)\n'
+  print('def linsolve(what, *args):')
+  print('  return getfem(\'linsolve\', what, *args)')
+  print('def compute(mf, U, what, *args):')
+  print('  return getfem(\'compute\', mf, U, what, *args)')
+  print('def asm(what, *args):')
+  print('  return getfem(\'asm\', what, *args)')
+  print('def util(what, *args):')
+  print('  return getfem(\'util\', what, *args)\n')
 
-  print '\ndef factory(id):'
+  print('\ndef factory(id):')
   sys.stdout.write('  t = ( ')
   ob = sorted(objects)
   first = True
@@ -1970,9 +1970,9 @@ def generic_destructor(self, destructible=True):
     if (not first): sys.stdout.write(',\n        ')
     sys.stdout.write(oname)
     first = False
-  print ')[id.classid]'
-  print '  return t(id)\n'
-  print 'register_python_factory(factory)'
+  print(')[id.classid]')
+  print('  return t(id)\n')
+  print('register_python_factory(factory)')
 
 
 
@@ -1992,17 +1992,17 @@ elif (option == 'python-doc'):
 
   langage = 'python'
 
-  print ".. Autogenerated by interface/bin/extract_doc. Do not edit it.\n"
-  print ".. include:: ../replaces.txt\n"
-  print ".. _api:\n"
-  print "API reference"
-  print "=============\n"
-  print ''
-  print 'Please remember that this documentation is not self contained.'
-  print 'You should in particular refer to the `user documentation`_ '
-  print 'to have a more extensive description of the structures algorithms '
-  print 'and concepts used.'
-  print ''
+  print(".. Autogenerated by interface/bin/extract_doc. Do not edit it.\n")
+  print(".. include:: ../replaces.txt\n")
+  print(".. _api:\n")
+  print("API reference")
+  print("=============\n")
+  print('')
+  print('Please remember that this documentation is not self contained.')
+  print('You should in particular refer to the `user documentation`_ ')
+  print('to have a more extensive description of the structures algorithms ')
+  print('and concepts used.')
+  print('')
 
   # one pass to find the set methods having identical name with a get method
   # in that case 'set_' is added to the set method.
@@ -2032,18 +2032,18 @@ elif (option == 'python-doc'):
   for o in ob:
     src_dir = directory + '/gf_' + o + '.cc'
     [oname, initiale] = StandardObjectName(o)
-    print ''
-    print oname
-    print '------------------------'
-    print '.. autoclass:: getfem.' + oname
-    print '  :members:\n'
+    print('')
+    print(oname)
+    print('------------------------')
+    print('.. autoclass:: getfem.' + oname)
+    print('  :members:\n')
     
   co = sorted(commands)
   for c in co:
     src_dir = directory + '/gf_' + c + '.cc'
     if (c != 'workspace' and os.path.exists(src_dir) and 
os.path.isfile(src_dir)):
-      print '\nModule ' + c
-      print '--------------------------\n'
+      print('\nModule ' + c)
+      print('--------------------------\n')
       [gdoc, args] = ExtractGlobalDoc(src_dir);
       gdoc = FilterDoc(gdoc, langage, objects, commands, set_replace)
       nbspace = -1; util_pos = -1; nbsp = -1
@@ -2078,14 +2078,14 @@ elif (option == 'python-doc'):
           if (nbspace >= 0):
               sys.stdout.write('  ' + l)
               
-      print ''
+      print('')
       fl = open(src_dir)
       doc = '';
       [ok, doc, dtype, mname, params, ret] = ExtractSubDoc(fl, langage)
       while (ok):
         mname = string.replace(mname, ' ', '_');
         mname = string.replace(mname, '-', '_');
-        print ''
+        print('')
         if (mname[0] == '.'):
           print('.. autofunction:: getfem.' + c)
         else:
@@ -2096,4 +2096,4 @@ elif (option == 'python-doc'):
 
 
 else:
-    print 'Unrecognized option. Valid options are ' + valid_options
+    print('Unrecognized option. Valid options are ' + valid_options)
diff --git a/bin/rst_to_xml.py b/bin/rst_to_xml.py
index 636af7a..e35d94b 100755
--- a/bin/rst_to_xml.py
+++ b/bin/rst_to_xml.py
@@ -123,7 +123,7 @@ for iform in range(count_math_f):
     temprst = open(filename+'_temp_f.tex', 'w')
     math_form = math_forms[iform];
     math_form = math_form.replace('\\mathscr', '\\cal')
-    print math_form
+    print(math_form)
     if (math_form.count('&')):
         temprst.write('\\begin{eqnarray*}\n')
         temprst.write(math_form[2:len(math_form)-2] + '\n')
@@ -136,11 +136,11 @@ for iform in range(count_math_f):
     for l in fl:
         if (l[:13] == '<formula type'):
             math_forms_trans.append(l)
-            print ("Formule %d : " % iform) + l
+            print(("Formule %d : " % iform) + l)
             break
         if (l[:16] == '<p><formula type'):
             math_forms_trans.append(l[3:])
-            print ("Formule %d : " % iform) + l
+            print(("Formule %d : " % iform) + l)
             break
     fl.close()
 
@@ -152,20 +152,20 @@ for l in fl:
         j = l.find("MATHZFORMULE")
         while (j != -1):
           r = l[j+12:j+18]
-          print r
+          print(r)
           nf = int(r)
-          print nf
-          print ("MATHZFORMULE%06d" % nf)
-          print math_forms_trans[nf-1]
+          print(nf)
+          print("MATHZFORMULE%06d" % nf)
+          print(math_forms_trans[nf-1])
           l = string.replace(l, ("MATHZFORMULE%06d" % nf), 
math_forms_trans[nf-1])
-          print l
+          print(l)
           j = l.find("MATHZFORMULE")
     rfl.write(l)
 rfl.close()
     
 
 
-print "there were ", count_math_f, " formulaes"
+print("there were ", count_math_f, " formulaes")
 
 
 
diff --git a/configure.ac b/configure.ac
index 6525491..676060a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -835,14 +835,6 @@ AC_ARG_WITH(matlab-toolbox-dir,
             TOOLBOXDIR="$withval",TOOLBOXDIR="$GFPREFIX/getfem_toolbox")
 AC_SUBST(TOOLBOXDIR)
 
-AC_ARG_ENABLE(python,
- [AS_HELP_STRING([--enable-python],[turn on/off python support])],
- [case "${enableval}" in
-   yes) usepython=YES ;;
-   no)  usepython=NO ;;
-   *) AC_MSG_ERROR([bad value ${enableval} for --enable-python]) ;;
- esac],[usepython=YES])
-
 if test "$usematlab" != NO; then
   AC_CHECK_PROGS(MEX, mex)
   if test x"$MEX" = x""; then
@@ -984,10 +976,27 @@ dnl ----------------------------------------------
 dnl python 
 dnl ----------------------------------------------
 
-if test x$usepython = xYES; then
-  AM_PATH_PYTHON(2.2, usepython=YES, usepython=NO)
+AC_ARG_ENABLE(python,
+ [AS_HELP_STRING([--enable-python],[turn on/off python support])],
+ [case "${enableval}" in
+   yes) usepython=YES ;;
+   no)  usepython=NO ;;
+   *) AC_MSG_ERROR([bad value ${enableval} for --enable-python]) ;;
+ esac],[usepython=YES])
+
+AC_ARG_ENABLE(python3,
+ [AS_HELP_STRING([--enable-python3],[turn on/off python3 (instead of python2) 
support])],
+ [case "${enableval}" in
+   yes) usepython3=YES ;;
+   no)  usepython3=NO ;;
+   *) AC_MSG_ERROR([bad value ${enableval} for --enable-python3]) ;;
+ esac],[usepython3=NO])
+
+if test x$usepython3 = xYES; then
+  AM_PATH_PYTHON(3.4, usepython=YES, usepython=NO)
+elif test x$usepython = xYES; then
+  AM_PATH_PYTHON(2.7, usepython=YES, usepython=NO)
 fi
-echo $PYTHON
 
 case $host in
     *mingw*)
@@ -1003,21 +1012,19 @@ esac
 AC_SUBST(PYTHON_CC_ARG)
 AC_SUBST(PYTHON_EXTRA_EXT_PARAM)
 
-
-
 if test "x$usepython" = "xYES"; then
-  echo "Building with python support (use --enable-python=no to disable it)"
+  echo "Building with python ($PYTHON) support (use --enable-python=no to 
disable it) "
   echo "You will need the python-numpy and python-scipy packages."
 dnl  AM_PATH_PYTHON(2.2)
   AC_PYTHON_DEVEL
-  ac_python_numpy=`$PYTHON -c 'import numpy; print "YES"' 2>/dev/null`
+  ac_python_numpy=`$PYTHON -c 'import numpy; print("YES")' 2>/dev/null`
   if  test "x$ac_python_numpy" != "xYES"; then
     usepython=NO
     MSG="PYTHON DISABLED: numpy not found. You need to install the 
python-numpy package."
     echo $MSG
     WARNING_MSG="$WARNING_MSG\n$MSG"
   fi
-  ac_python_scipy=`$PYTHON -c 'import scipy; print "YES"' 2>/dev/null`
+  ac_python_scipy=`$PYTHON -c 'import scipy; print("YES")' 2>/dev/null`
   if  test "x$ac_python_scipy" != "xYES"; then
     usepython=NO
     MSG="PYTHON DISABLED: scipy not found. You need to install the 
python-scipy package."
@@ -1025,7 +1032,7 @@ dnl  AM_PATH_PYTHON(2.2)
     WARNING_MSG="$WARNING_MSG\n$MSG"
   fi
   if  test $paralevel -ge 1; then
-    ac_python_mpi4py=`$PYTHON -c 'import mpi4py; print "YES"' 2>/dev/null`
+    ac_python_mpi4py=`$PYTHON -c 'import mpi4py; print("YES")' 2>/dev/null`
     if test "x$ac_python_mpi4py" != "xYES"; then
       usepython=NO
       MSG="PARALLEL PYTHON DISABLED: mpi4py not found. You need to install the 
python-mpi4py package."
diff --git a/contrib/test_plasticity/Makefile.am 
b/contrib/test_plasticity/Makefile.am
index 986eaba..8baae31 100644
--- a/contrib/test_plasticity/Makefile.am
+++ b/contrib/test_plasticity/Makefile.am
@@ -25,7 +25,7 @@ TESTS = test_plasticity.py
 AM_TESTS_ENVIRONMENT = \
        export PYTHONPATH=$(top_builddir)/interface/src/python; \
        export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(top_builddir)/src/.libs;
-LOG_COMPILER = python
+LOG_COMPILER = $(PYTHON)
 endif
 
 EXTRA_DIST = \
diff --git a/contrib/test_plasticity/test_plasticity.py 
b/contrib/test_plasticity/test_plasticity.py
index d3ecba6..da70964 100644
--- a/contrib/test_plasticity/test_plasticity.py
+++ b/contrib/test_plasticity/test_plasticity.py
@@ -36,7 +36,7 @@ with_graphics=True
 try:
     import getfem_tvtk
 except:
-    print "\n** Could NOT import getfem_tvtk -- graphical output disabled **\n"
+    print("\n** Could NOT import getfem_tvtk -- graphical output disabled 
**\n")
     import time
     time.sleep(2)
     with_graphics=False
@@ -92,9 +92,9 @@ nbstep = F.shape[0]
 
 dd=mf0.basic_dof_from_cvid()
 
-print 'nbstep:', nbstep
+print('nbstep:', nbstep)
 for step in range(0, nbstep):
-    print 'step %d' % (step,)
+    print('step %d' % (step,))
     md.set_variable('VolumicData', [F[step,0],F[step,1]])
     md.solve('noisy', 'lsearch', 'simplest',  'alpha min', 0.8, 'max_iter', 
100, 'max_res', 1e-6)
     U = md.variable('u')
@@ -115,5 +115,5 @@ for step in range(0, nbstep):
     if with_graphics:
         fig = getfem_tvtk.Figure()
         fig.show(mfu, deformation=U, deformation_scale=1, data=(mfdu,VM))
-        print "Press Q to continue.."
+        print("Press Q to continue..")
         fig.loop()
diff --git a/doc/sphinx/source/install/install_linux.rst 
b/doc/sphinx/source/install/install_linux.rst
index 069de9b..4dbcc9b 100644
--- a/doc/sphinx/source/install/install_linux.rst
+++ b/doc/sphinx/source/install/install_linux.rst
@@ -101,6 +101,14 @@ Configure Options
 
     $ ./configure --prefix=my_dest_dir
 
+* By default, the python interface is built and for python 2 version. You can 
disable the built of the python interface with::
+
+    $ ./configure --disable-python
+
+  or either build the interface for python 3 version with
+
+    $ ./configure --enable-python3
+
 
 Note that there are other options to the configure script. A
 ``./configure --help`` will list them.
diff --git a/doc/sphinx/source/install/install_mac.rst 
b/doc/sphinx/source/install/install_mac.rst
index 17b3f3d..0e4fe9b 100644
--- a/doc/sphinx/source/install/install_mac.rst
+++ b/doc/sphinx/source/install/install_mac.rst
@@ -118,7 +118,13 @@ Configure Options
     $ ./configure ``--enable-matlab``
 
   depending on the interface you want to build. Note that the python interface
-  is build by default.
+  is build by default and for python 2 version. If you want to build the
+  python 3 interface use::
+
+    $ ./configure ``--enable-python3``
+
+  In that case, you have of course to install a python 3 version on your system
+  together with at least ``numpy`` and ``scipy`` packages.
 
 * If you want to use a specific **BLAS** library, you may have to
   supply the necessary link flags and libs to the configure script
diff --git a/doc/sphinx/source/install/install_windows.rst 
b/doc/sphinx/source/install/install_windows.rst
index 20de47c..a84540b 100644
--- a/doc/sphinx/source/install/install_windows.rst
+++ b/doc/sphinx/source/install/install_windows.rst
@@ -135,8 +135,8 @@ Build with the Python interface
 
 Additionnaly to build the Python interface, you will have first to install a 
64bits version of Python 2 on your system together with Numpy and Scipy 
packages. This is not completely simple, but you can follow the following steps 
 
-  - Install a 64 bits Python 2 version
-    (see `Python 2 <https://www.python.org/downloads/windows/>`_).
+  - Install a 64 bits Python 2 or 3 version
+    (see `Python website <https://www.python.org/downloads/windows/>`_).
     Then, if it is not done by the installer you used, add ``C:\Pythonxx``
     to your Windows path (where ``xx`` is the version number).
     Close you Msys and Windows shell and re-open them to take into
@@ -145,9 +145,10 @@ Additionnaly to build the Python interface, you will have 
first to install a 64b
   - Install Pip (see `Pip <https://pip.pypa.io/en/latest/installing/>`_)
 
   - Downloads the precompiled packages of numpy and scipy for 64 bits
-    and Python 2 `here <http://www.lfd.uci.edu/~gohlke/pythonlibs/>`_
-    (i.e. the wheel packages `numpy-1.11.3+mkl-cp27-cp27m-win_amd64.whl`
-    and `scipy-0.19.0-cp27-cp27m-win_amd64.whl`).
+    and Python `here <http://www.lfd.uci.edu/~gohlke/pythonlibs/>`_
+    (i.e. for isntance wheel packages
+    ``numpy-1.11.3+mkl-cp27-cp27m-win_amd64.whl``
+    and ``scipy-0.19.0-cp27-cp27m-win_amd64.whl`` for python 2).
 
   - Enter into the directory where you downloaded the two
     wheel Python packages and install them with::
@@ -178,7 +179,7 @@ Build with the Matlab interface
 
 Here follows the additional step to build the Matlab interface. You have 
first, of course to have installed a (recent) version of Matlab on your system.
 
-  - You also need a installation of Python 2, because some Python scripts
+  - You also need a installation of Python, because some Python scripts
     are used to build the interface. You can follow the steps described
     in the previous section for Python interface installation.
     However, for the Matlab interface, Numpy and Scipy are not required.
diff --git a/doc/sphinx/source/userdoc/gasm_high.rst 
b/doc/sphinx/source/userdoc/gasm_high.rst
index 6061a01..b59d2ec 100644
--- a/doc/sphinx/source/userdoc/gasm_high.rst
+++ b/doc/sphinx/source/userdoc/gasm_high.rst
@@ -568,10 +568,12 @@ The assembly language provide some predefined nonlinear 
operator. Each nonlinear
 
   - ``Norm_sqr(v)`` for ``v`` a vector or a matrix gives the square of the 
euclidean norm of a vector or of the |Frobenius| norm of a matrix. For a vector 
this is equivalent to ``v.v`` and for a matrix to ``m:m``.
 
-  - ``Normalized(v)`` for ``v`` a vector or a matrix gives ``v`` divided by 
its euclidean (for vectors) or |Frobenius| (for matrices) norm. In order to 
avoid problems when ``v`` is close to 0, it is implemented as 
``Normalized_reg(v, 1E-25)``. Use with care. Think that the derivative at the 
origin of ``Normalized(v)*Norm(v)`` is wrong (it vanishes) and very different 
from the deivative of ``v``.
+  - ``Normalized(v)`` for ``v`` a vector or a matrix gives ``v`` divided by 
its euclidean (for vectors) or |Frobenius| (for matrices) norm. In order to 
avoid problems when ``v`` is close to 0, it is implemented as 
``Normalized_reg(v, 1E-25)``. Use with care. Think that the derivative at the 
origin of ``Normalized(v)*Norm(v)`` is wrong (it vanishes) and very different 
from the derivative of ``v``.
 
   - ``Normalized_reg(v, eps)`` for ``v`` a vector or a matrix gives a 
regularized version of ``Normalized(v)`` : ``v/sqrt(|v|*|v|+eps*eps)``.
 
+  - ``Ball_projection(v, r)`` for ``v`` a vector or a matrix and ``r`` a 
scalar, gives the projection of ``v`` on the ball of radius ``r`` and center 
the origin.
+
   - ``Det(m)`` gives the determinant of a square matrix ``m``.
 
   - ``Inv(m)`` gives the inverse of a square matrix ``m``. The second 
derivative is not available since it is an order 6 tensor. This means that 
``Inv(m)`` cannot be used in the description of a potential energy.
diff --git a/interface/src/gf_mesh_fem_get.cc b/interface/src/gf_mesh_fem_get.cc
index 17a0943..21d9587 100644
--- a/interface/src/gf_mesh_fem_get.cc
+++ b/interface/src/gf_mesh_fem_get.cc
@@ -970,18 +970,18 @@ void gf_mesh_fem_get(getfemint::mexargs_in& m_in,
       nbd = P.shape[1]
     vars = ('x','y','z','u','v','w')
     nbvars = min(P.shape[0],len(vars))
-    for i in xrange(0,nbvars):
+    for i in range(0,nbvars):
       gl[vars[i]] = P[i,0]
       lo[vars[i]] = P[i,0]
     ccode = compile(expression, '<string>', 'eval');
     r = numpy.array(eval(ccode,gl,lo))
     Z = numpy.zeros(r.shape + (nbd,), r.dtype)
-    nbd_p = nbd/nbp
+    nbd_p = int(nbd/nbp)
     nbd_end = nbd_p*(rk+1)
     if (rk == nbp-1):
       nbd_end = nbd
-    for j in xrange(nbd_p*rk,nbd_end):
-      for i in xrange(0,nbvars):
+    for j in range(nbd_p*rk,nbd_end):
+      for i in range(0,nbvars):
         gl[vars[i]] = P[i,j]
         lo[vars[i]] = P[i,j]
       Z[...,j] = eval(ccode,gl,lo)
diff --git a/interface/src/python/Makefile.am b/interface/src/python/Makefile.am
index d9fa72c..9e18ef1 100644
--- a/interface/src/python/Makefile.am
+++ b/interface/src/python/Makefile.am
@@ -55,15 +55,10 @@ getfem_python_c.c : getfem_python.c
 # ARCHFLAGS is set to empty to disable universal binaries with python 2.5 on 
macos 10.5
 _getfem.so: getfem_python_c.c ../libgetfemint.la $(GETFEM_LIB_LA)
        touch _getfem.so && rm _getfem.so
-       ARCHFLAGS="" CC="$(CC)" CFLAGS="$(CFLAGS)" python setup.py -v build 
@PYTHON_CC_ARG@ --build-temp . --build-base . --build-lib . --force
+       ARCHFLAGS="" CC="$(CC)" CFLAGS="$(CFLAGS)" $(PYTHON) setup.py -v build 
@PYTHON_CC_ARG@ --build-temp . --build-base . --build-lib . --force
 #LDSHARED="$(CXX) -shared" ARCHFLAGS="" python setup.py -v build --build-temp 
. --build-base . --build-lib . --force
 
 
-# getfem_python_reference.html: getfem.py _getfem.so
-#      cp getfem.py getfem_python_reference.py
-#      (export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):../../../src/.libs && pydoc 
-w getfem_python_reference) &&  if test -d $(top_srcdir)/interface/doc; then cp 
getfem_python_reference.html 
$(top_srcdir)/interface/doc/getfem_python_reference.html; fi;
-#      rm -f getfem_python_reference.py
-
 all: _getfem.so getfem.py
 #pyexec_LTLIBRARIES = libgfpython.la
 #libgfpython_la_LIBADD = ../.libs/libgetfemint.a @GETFEM_STATICLIBS@
diff --git a/interface/src/python/getfem_python.c 
b/interface/src/python/getfem_python.c
index 7816c82..ad08299 100644
--- a/interface/src/python/getfem_python.c
+++ b/interface/src/python/getfem_python.c
@@ -34,7 +34,16 @@
 #include "getfem_arch_config.h"
 #include <assert.h>
 
-
+#if PY_MAJOR_VERSION >= 3
+#define PyString_AsString(o) PyUnicode_AsUTF8(o)
+#define PyString_FromFormat(a,b,c) PyUnicode_FromFormat(a,b,c)
+#define PyString_Check(o) PyUnicode_Check(o)
+#define PyInt_Check(o) PyLong_Check(o)
+#define PyInt_AsLong(o) PyLong_AsLong(o)
+#define PyString_FromString(o) PyUnicode_FromString(o)
+#define PyString_FromStringAndSize(o,l) PyUnicode_FromStringAndSize(o,l)
+#define PyInt_FromLong(o) PyLong_FromLong(o)
+#endif
 
 static PyObject *call_getfem(PyObject *self, PyObject *args);
 static PyObject *getfem_env(PyObject *self, PyObject *args);
@@ -53,8 +62,7 @@ typedef struct PyGetfemObject {
 } PyGetfemObject;
 
 static PyObject *
-GetfemObject_name(PyGetfemObject *self)
-{
+GetfemObject_name(PyGetfemObject *self) {
   return PyString_FromFormat("getfem.GetfemObject(classid=%d,objid=%d)",
                              self->classid, self->objid);
 }
@@ -67,8 +75,24 @@ GetfemObject_hash(PyGetfemObject *key) {
 static int
 GetfemObject_compare(PyGetfemObject *self, PyGetfemObject *other) {
   if (self->classid < other->classid) return -1;
-  else if (self->objid < other->objid) return +1;
-  else return 0;
+  if (self->classid > other->classid) return +1;
+  if (self->objid < other->objid) return -1;
+  if (self->objid > other->objid) return +1;
+  return 0;
+}
+
+static PyObject *
+GfObject_richcompare(PyGetfemObject *self, PyGetfemObject *other, int op) {
+  int bc = GetfemObject_compare(self, other);
+  switch(op) {
+  case Py_LT : if (bc <  0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+  case Py_LE : if (bc <= 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+  case Py_EQ : if (bc == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+  case Py_NE : if (bc != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+  case Py_GT : if (bc == 1) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+  case Py_GE : if (bc >= 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
+  }
+  return NULL;
 }
 
 static PyMethodDef module_methods[] = {
@@ -101,8 +125,12 @@ static PyMemberDef GetfemObject_members[] = {
 };
 
 static PyTypeObject PyGetfemObject_Type = {
+#if PY_MAJOR_VERSION >= 3
+    PyVarObject_HEAD_INIT(NULL, 0)
+#else
     PyObject_HEAD_INIT(NULL)
     0,                                 /* ob_size (deprecated) */
+#endif
     "_getfem.GetfemObject",            /* tp_name */
     sizeof(PyGetfemObject),            /* tp_basicsize */
     0,                                 /* tp_itemsize */
@@ -110,7 +138,11 @@ static PyTypeObject PyGetfemObject_Type = {
     0,                                 /* tp_print */
     0,                                 /* tp_getattr */
     0,                                 /* tp_setattr */
+#if PY_MAJOR_VERSION >= 3
+    GetfemObject_compare,              /* tp_compare, necessary for 
dictionary*/
+#else
     (cmpfunc)GetfemObject_compare,     /* tp_compare, necessary for 
dictionary*/
+#endif
     0,                                 /* tp_repr */
     0,                                 /* tp_as_number */
     0,                                 /* tp_as_sequence */
@@ -125,7 +157,7 @@ static PyTypeObject PyGetfemObject_Type = {
     "Generic GetFEM objects",          /* tp_doc */
     0,                                 /* tp_traverse */
     0,                                 /* tp_clear */
-    0,                                 /* tp_richcompare */
+    (richcmpfunc)GfObject_richcompare, /* tp_richcompare */
     0,                                 /* tp_weaklistoffset */
     0,                                 /* tp_iter */
     0,                                 /* tp_iternext */
@@ -153,6 +185,37 @@ static PyTypeObject PyGetfemObject_Type = {
 #ifndef PyMODINIT_FUNC        /* declarations for DLL import/export */
 #define PyMODINIT_FUNC void
 #endif
+
+#if PY_MAJOR_VERSION >= 3
+
+static struct PyModuleDef moduledef = {
+  PyModuleDef_HEAD_INIT,
+  "_getfem",     /* m_name */
+  "getfem-python3 interface module.",  /* m_doc */
+  -1,                  /* m_size */
+  module_methods,    /* m_methods */
+  NULL,                /* m_reload */
+  NULL,                /* m_traverse */
+  NULL,                /* m_clear */
+  NULL,                /* m_free */
+};
+
+PyMODINIT_FUNC
+PyInit__getfem(void)
+{
+  PyObject *m;
+  PyGetfemObject_Type.tp_new = PyType_GenericNew;
+  if (PyType_Ready(&PyGetfemObject_Type) < 0)
+    return NULL;
+  m = PyModule_Create(&moduledef);
+  import_array(); /* init Numpy */
+  Py_INCREF(&PyGetfemObject_Type);
+  PyModule_AddObject(m, "GetfemObject", (PyObject *)&PyGetfemObject_Type);
+  return m;
+}
+
+#else
+
 PyMODINIT_FUNC
 init_getfem(void)
 {
@@ -167,7 +230,7 @@ init_getfem(void)
   PyModule_AddObject(m, "GetfemObject", (PyObject *)&PyGetfemObject_Type);
 }
 
-
+#endif
 
 #define COLLECTCHUNK 2
 typedef struct ptr_collect {
diff --git a/interface/tests/python/Makefile.am 
b/interface/tests/python/Makefile.am
index c2ab452..150597e 100644
--- a/interface/tests/python/Makefile.am
+++ b/interface/tests/python/Makefile.am
@@ -60,7 +60,7 @@ TESTS =                                               \
 AM_TESTS_ENVIRONMENT = \
        export PYTHONPATH=$(top_builddir)/interface/src/python; \
        export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH):$(top_builddir)/src/.libs;
-LOG_COMPILER = python
+LOG_COMPILER = $(PYTHON)
 endif
 
 CLEANFILES = *.vtk *.dx *.pyc tank_3D* tripod* plate* *.pos *.dx
diff --git a/interface/tests/python/check_export.py 
b/interface/tests/python/check_export.py
index 036a34d..fc7e9f1 100644
--- a/interface/tests/python/check_export.py
+++ b/interface/tests/python/check_export.py
@@ -76,7 +76,7 @@ mf1.export_to_vtk('check_export3.vtk','ascii')
 try:
     m0.export_to_dx('check_export0.dx')
 except RuntimeError as detail:
-    print detail
+    print(detail)
 
 m1.export_to_dx('check_export0.dx','ascii','edges')
 m1.export_to_dx('check_export0.dx','ascii','append')
diff --git a/interface/tests/python/check_levelset.py 
b/interface/tests/python/check_levelset.py
index 7c934b7..7c9d5fc 100644
--- a/interface/tests/python/check_levelset.py
+++ b/interface/tests/python/check_levelset.py
@@ -56,7 +56,7 @@ if True:
   mls.add(ls3)
 mls.adapt()
 
-#print mls.linked_mesh()
+#print(mls.linked_mesh())
 
 lls = mls.levelsets()
 
diff --git a/interface/tests/python/demo_crack.py 
b/interface/tests/python/demo_crack.py
index 601cd1e..57a1524 100644
--- a/interface/tests/python/demo_crack.py
+++ b/interface/tests/python/demo_crack.py
@@ -33,7 +33,7 @@ except ImportError:
   sys.path.append('../../src/python/')
   import getfem as gf
 else:
-  print "module getfem not found!"
+  print("module getfem not found!")
 
 import numpy as np
 import math
@@ -187,5 +187,5 @@ VM = 
md.compute_isotropic_linearized_Von_Mises_or_Tresca('u_cut', 'lambda', 'mu'
 
 mfv.export_to_pos('crack.pos', V, 'V', Ve, 'Ve', mfvm, VM, 'Von Mises')
 
-print 'You can view the solution with (for example):'
-print 'gmsh crack.pos'
+print('You can view the solution with (for example):')
+print('gmsh crack.pos')
diff --git a/interface/tests/python/demo_fictitious_domains.py 
b/interface/tests/python/demo_fictitious_domains.py
index 75d8318..67302af 100644
--- a/interface/tests/python/demo_fictitious_domains.py
+++ b/interface/tests/python/demo_fictitious_domains.py
@@ -51,8 +51,8 @@ y = P[1,:]
 ULS = 1000*np.ones(x.shape)
 
 if True:
-  for ix in xrange(0,5):
-    for iy in xrange(0,5):
+  for ix in range(0,5):
+    for iy in range(0,5):
       xc = (ix/4) * 0.8 - 0.4
       yc = (iy/4) * 0.8 - 0.4
       if (iy%2)==1:
@@ -62,7 +62,7 @@ if True:
       R = 0.03 + 0.005*iy
       ULS = np.minimum(ULS, ((x - xc)**2 + (y - yc)**2) - R**2);
 else:
-  for i in xrange(8):
+  for i in range(8):
     xc = rand() - 0.5
     yc = rand() - 0.5
     R = rand() * 0.09 + 0.02
@@ -71,7 +71,7 @@ ls.set_values(ULS)
 
 ULS2 = 1000*np.ones(x.shape);
 ULS2s = 1000*np.ones(x.shape);
-for i in xrange(1):
+for i in range(1):
   xc = 0.0 # rand() - 0.5
   yc = 0.0 # rand() - 0.5
   theta = np.pi/3 # np.pi*rand()
@@ -132,5 +132,5 @@ mfdu.export_to_pos('vm.pos', VM, 'Von Mises', mfu0, U, 
'deformation')
 
 mf_ls.export_to_pos('ls.pos',ls.values(0),'ls values 0')
 
-print 'You can view the solution with (for instance):'
-print 'gmsh vm.pos ls.pos'
+print('You can view the solution with (for instance):')
+print('gmsh vm.pos ls.pos')
diff --git a/interface/tests/python/demo_laplacian.py 
b/interface/tests/python/demo_laplacian.py
index 661f5db..377af37 100644
--- a/interface/tests/python/demo_laplacian.py
+++ b/interface/tests/python/demo_laplacian.py
@@ -126,16 +126,16 @@ md.solve()
 U = md.variable('u')
 L2error = gf.compute(mfu, U-Ue, 'L2 norm', mim)
 H1error = gf.compute(mfu, U-Ue, 'H1 norm', mim)
-print 'Error in L2 norm : ', L2error
-print 'Error in H1 norm : ', H1error
+print('Error in L2 norm : ', L2error)
+print('Error in H1 norm : ', H1error)
 
 # Export data
 mfu.export_to_pos('laplacian.pos', Ue,'Exact solution',
                                     U,'Computed solution')
-print 'You can view the solution with (for example):'
-print 'gmsh laplacian.pos'
+print('You can view the solution with (for example):')
+print('gmsh laplacian.pos')
 
 
 if (H1error > 1e-3):
-    print 'Error too large !'
+    print('Error too large !')
     exit(1)
diff --git a/interface/tests/python/demo_laplacian_DG.py 
b/interface/tests/python/demo_laplacian_DG.py
index 447a1a0..dccc575 100644
--- a/interface/tests/python/demo_laplacian_DG.py
+++ b/interface/tests/python/demo_laplacian_DG.py
@@ -83,7 +83,7 @@ if (verify_neighbour_computation):
   TEST_FACES=5
   adjf = m.adjacent_face(42, 0);
   if (len(adjf) != 2):
-    print ('No adjacent edge found, change the element number')
+    print('No adjacent edge found, change the element number')
     exit(1)
   m.set_region(TEST_FACES, np.array([[42,adjf[0][0]], [0,adjf[1][0]]]));
   
@@ -156,14 +156,14 @@ md.solve()
 U = md.variable('u')
 L2error = gf.compute(mfu, U-Ue, 'L2 norm', mim)
 H1error = gf.compute(mfu, U-Ue, 'H1 norm', mim)
-print 'Error in L2 norm : ', L2error
-print 'Error in H1 norm : ', H1error
+print('Error in L2 norm : ', L2error)
+print('Error in H1 norm : ', H1error)
 
 # Export data
 mfu.export_to_pos('laplacian.pos', Ue,'Exact solution',
                                     U,'Computed solution')
-print 'You can view the solution with (for example):'
-print 'gmsh laplacian.pos'
+print('You can view the solution with (for example):')
+print('gmsh laplacian.pos')
 
 if (verify_neighbour_computation):
   A=gf.asm('generic', mim, 1, 'u*Test_u*(Normal.Normal)', TEST_FACES, md)
@@ -173,10 +173,10 @@ if (verify_neighbour_computation):
   B=gf.asm('generic', mim, 1, 
'(Interpolate(Grad_u,neighbour_elt).Normal)*(Interpolate(Grad_Test_u,neighbour_elt).Normal)',
 TEST_FACES, md)
   err_v = err_v + np.linalg.norm(A-B)
   if (err_v > 1E-13):
-    print 'Test on neighbour element computation: error to big: ', err_v
+    print('Test on neighbour element computation: error to big: ', err_v)
     exit(1)
   
 if (H1error > 1e-3):
-    print 'Error too large !'
+    print('Error too large !')
     exit(1)
 
diff --git a/interface/tests/python/demo_laplacian_aposteriori.py 
b/interface/tests/python/demo_laplacian_aposteriori.py
index 56a88f8..ea229cd 100644
--- a/interface/tests/python/demo_laplacian_aposteriori.py
+++ b/interface/tests/python/demo_laplacian_aposteriori.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2015-2017 Yves Renard
@@ -105,56 +106,57 @@ else:
                                                LEFT_BOUND)
 
 for refiter in range(5):
-
-       if (export_mesh):
-               mesh.export_to_vtk('mesh%d.vtk'%refiter);
-               print ('\nYou can view the mesh for instance with');
-               print ('mayavi2 -d mesh%d.vtk -f ExtractEdges -m Surface 
\n'%refiter);
-               
-       # Assembly of the linear system and solve.
-       md.solve()
-
-       # Main unknown
-       U = md.variable('u')
-
-       # Residual a posteriori estimator
-
-       grad_jump = '( (Grad_u-Interpolate(Grad_u,neighbour_elt)).Normal )'
-
-       bulkresidual = 'sqr(element_size*Trace(Hess_u))*Test_psi'
-       edgeresidual = '0.25*element_size*sqr(%s)*(Test_psi + 
Interpolate(Test_psi,neighbour_elt))'%grad_jump
-
-       ETA1tmp = 
gf.asm('generic',mim,1,bulkresidual,-1,md,'psi',1,mfP0,np.zeros(mfP0.nbdof()))
-       ETA1 = ETA1tmp [ ETA1tmp.size - mfP0.nbdof() : ETA1tmp.size ]
-       ETA2tmp = 
gf.asm('generic',mim,1,edgeresidual,INNER_FACES,md,'psi',1,mfP0,np.zeros(mfP0.nbdof()))
-       ETA2 = ETA2tmp [ ETA2tmp.size - mfP0.nbdof() : ETA2tmp.size ]
-       ETA  = np.sqrt ( ETA1 + ETA2 )
-
-       # Export data
-       mfu.export_to_pos('laplacian%d.pos'%refiter, U, 'Computed solution')
-       print 'You can view the solution with (for example):'
-       print 'gmsh laplacian%d.pos'%refiter
-
-       mfP0.export_to_pos('eta1_%d.pos'%refiter, ETA1, 'Bulk residual')
-       print 'You can view eta1 with (for example):'
-       print 'gmsh eta1_%d.pos'%refiter
-
-       mfP0.export_to_pos('eta2_%d.pos'%refiter, ETA2, 'Edge residual')
-       print 'You can view eta2 with (for example):'
-       print 'gmsh eta2_%d.pos'%refiter
-
-       mfu.export_to_vtk('laplacian%d.vtk'%refiter, mfu, U, 'u', mfP0, ETA1, 
'eta1', mfP0, ETA2, 'eta2')
-       print ('mayavi2 -d laplacian%d.vtk -f WarpScalar -m Surface'%refiter)
-
-       # Refine the mesh
-       dd=mfP0.basic_dof_from_cvid()
-
-       ETAElt = np.zeros(dd[0].size)
-       for i in range(dd[0].size):
-               ETAElt[i] = ETA[ dd[0][i] ] 
-
-       mesh.refine(np.where( ETAElt > 0.6*np.max(ETA) ))
-       mesh.optimize_structure()
+    
+    if (export_mesh):
+      mesh.export_to_vtk('mesh%d.vtk' % refiter)
+    
+    print('\nYou can view the mesh for instance with')
+    print('mayavi2 -d mesh%d.vtk -f ExtractEdges -m Surface \n'%refiter)
+    
+    # Assembly of the linear system and solve.
+    md.solve()
+    
+    # Main unknown
+    U = md.variable('u')
+    
+    # Residual a posteriori estimator
+    
+    grad_jump = '( (Grad_u-Interpolate(Grad_u,neighbour_elt)).Normal )'
+
+    bulkresidual = 'sqr(element_size*Trace(Hess_u))*Test_psi'
+    edgeresidual = '0.25*element_size*sqr(%s)*(Test_psi + 
Interpolate(Test_psi,neighbour_elt))'%grad_jump
+
+    ETA1tmp = 
gf.asm('generic',mim,1,bulkresidual,-1,md,'psi',1,mfP0,np.zeros(mfP0.nbdof()))
+    ETA1 = ETA1tmp [ ETA1tmp.size - mfP0.nbdof() : ETA1tmp.size ]
+    ETA2tmp = 
gf.asm('generic',mim,1,edgeresidual,INNER_FACES,md,'psi',1,mfP0,np.zeros(mfP0.nbdof()))
+    ETA2 = ETA2tmp [ ETA2tmp.size - mfP0.nbdof() : ETA2tmp.size ]
+    ETA  = np.sqrt ( ETA1 + ETA2 )
+    
+    # Export data
+    mfu.export_to_pos('laplacian%d.pos'%refiter, U, 'Computed solution')
+    print('You can view the solution with (for example):')
+    print('gmsh laplacian%d.pos'%refiter)
+    
+    mfP0.export_to_pos('eta1_%d.pos'%refiter, ETA1, 'Bulk residual')
+    print('You can view eta1 with (for example):')
+    print('gmsh eta1_%d.pos'%refiter)
+    
+    mfP0.export_to_pos('eta2_%d.pos'%refiter, ETA2, 'Edge residual')
+    print('You can view eta2 with (for example):')
+    print('gmsh eta2_%d.pos'%refiter)
+    
+    mfu.export_to_vtk('laplacian%d.vtk'%refiter, mfu, U, 'u', mfP0, ETA1, 
'eta1', mfP0, ETA2, 'eta2')
+    print('mayavi2 -d laplacian%d.vtk -f WarpScalar -m Surface'%refiter)
+    
+    # Refine the mesh
+    dd=mfP0.basic_dof_from_cvid()
+    
+    ETAElt = np.zeros(dd[0].size)
+    for i in range(dd[0].size):
+        ETAElt[i] = ETA[ dd[0][i] ] 
+    
+    mesh.refine(np.where( ETAElt > 0.6*np.max(ETA) ))
+    mesh.optimize_structure()
 
 
 
diff --git a/interface/tests/python/demo_laplacian_pyramid.py 
b/interface/tests/python/demo_laplacian_pyramid.py
index f4e89a6..50abe33 100644
--- a/interface/tests/python/demo_laplacian_pyramid.py
+++ b/interface/tests/python/demo_laplacian_pyramid.py
@@ -59,8 +59,8 @@ mfrhs.set_fem(gf.Fem('FEM_PYRAMID_LAGRANGE(2)'))
 
 if (export_mesh):
   m.export_to_vtk('mesh.vtk');
-  print ('\nYou can view the mesh for instance with');
-  print ('mayavi2 -d mesh.vtk -f ExtractEdges -m Surface \n');
+  print('\nYou can view the mesh for instance with');
+  print('mayavi2 -d mesh.vtk -f ExtractEdges -m Surface \n');
 
 
 #  Integration method used
@@ -144,22 +144,22 @@ md.solve()
 U = md.variable('u')
 L2error = gf.compute(mfu, U-Ue, 'L2 norm', mim)
 H1error = gf.compute(mfu, U-Ue, 'H1 norm', mim)
-print 'Error in L2 norm : ', L2error
-print 'Error in H1 norm : ', H1error
+print('Error in L2 norm : ', L2error)
+print('Error in H1 norm : ', H1error)
 UU = np.zeros(U.size);
 UU[4] = 1.;
 
 # Export data
 mfu.export_to_pos('laplacian.pos', Ue, 'Exact solution',
                   U, 'Computed solution', UU, 'Test field')
-print 'You can view the solution with (for example):'
-print 'gmsh laplacian.pos'
+print('You can view the solution with (for example):')
+print('gmsh laplacian.pos')
 
 mfu.export_to_vtk('laplacian.vtk', mfu, Ue, 'Exact solution', mfu, U, 
'Computed solution', mfu, UU, 'Test field');
-print ('\nYou can view the solution for instance with');
-print ('mayavi2 -d laplacian.vtk -m Surface \n');
+print('\nYou can view the solution for instance with');
+print('mayavi2 -d laplacian.vtk -m Surface \n');
 
 
 if (H1error > 0.09):
-    print 'Error too large !'
+    print('Error too large !')
     exit(1)
diff --git a/interface/tests/python/demo_navier_stokes.py 
b/interface/tests/python/demo_navier_stokes.py
index 0f99764..8cf9e18 100644
--- a/interface/tests/python/demo_navier_stokes.py
+++ b/interface/tests/python/demo_navier_stokes.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2015 Konstantinos Poulios.
@@ -117,7 +117,6 @@ md.add_nonlinear_generic_assembly_brick\
 mmat_v = gf.asm_mass_matrix(mim, mfv)
 #mmat_v = gf.asm_generic(mim, 2, "Test2_v.Test_v", -1, "v", 1, mfv, 
np.zeros(mfv.nbdof()))
 IV = md.interval_of_variable("v")
-IV = range(IV[0],IV[0]+IV[1])
 
 t = 0
 step = 0
@@ -127,7 +126,7 @@ while t < T+1e-8:
    ("p_in", mfp_.eval(p_in_str.format(t), globals(), locals()).flatten("F"))
    md.set_variable("v0", md.variable("v"))
    md.solve("noisy", "lsolver", "mumps", "max_res", 1e-8)
-   vv = gf.asm_generic(mim, 1, "(v-dt*Grad_p).Test_v", -1, md)[IV]
+   vv = (gf.asm_generic(mim, 1, "(v-dt*Grad_p).Test_v", -1, 
md))[IV[0]:IV[0]+IV[1]]
    md.set_variable("v", gf.linsolve_mumps(mmat_v, vv))
 
    mfv.export_to_vtk("results_%i.vtk" % step,
diff --git a/interface/tests/python/demo_nonlinear_elasticity.py 
b/interface/tests/python/demo_nonlinear_elasticity.py
index 15f1ad3..6d2c6ab 100644
--- a/interface/tests/python/demo_nonlinear_elasticity.py
+++ b/interface/tests/python/demo_nonlinear_elasticity.py
@@ -30,7 +30,7 @@ gf.util_trace_level(1)
 dirichlet_version = 2          # 1 = simplification, 2 = penalisation
 test_tangent_matrix = False    # Test or not tangent system validity
 incompressible = False;        # Incompressibility option
-explicit_potential = True;     # Elasticity law with explicit potential
+explicit_potential = False;    # Elasticity law with explicit potential
 
 # lawname = 'Ciarlet Geymonat'
 # params = [1.,1.,0.25]
@@ -81,7 +81,7 @@ md.add_initialized_data('params', params)
 if (not(explicit_potential)):
     md.add_finite_strain_elasticity_brick(mim, lawname, 'u', 'params')
 else:
-    print "Explicit elastic potential"
+    print("Explicit elastic potential")
     K = 1.2; mu = 3.0;
     _F_ = "(Id(3)+Grad_u)"
     _J_= "Det{F}".format(F=_F_)
diff --git a/interface/tests/python/demo_parallel_laplacian.py 
b/interface/tests/python/demo_parallel_laplacian.py
index b9978f9..5a01ed0 100644
--- a/interface/tests/python/demo_parallel_laplacian.py
+++ b/interface/tests/python/demo_parallel_laplacian.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2004-2009 Yves Renard, Julien Pommier.
@@ -37,9 +37,9 @@ import time
 
 rank = mpi.COMM_WORLD.rank
 if (rank == 0):
-  print 'Running Parallel Getfem with python interface'
+  print('Running Parallel Getfem with python interface')
 
-print 'Hello from thread ', rank
+print('Hello from thread ', rank)
 
 ## Parameters
 NX = 100                           # Mesh parameter.
@@ -52,7 +52,7 @@ t = time.clock()
 # creation of a simple cartesian mesh
 m = gf.Mesh('regular_simplices', np.arange(0,1+1./NX,1./NX), 
np.arange(0,1+1./NX,1./NX))
 if (rank == 0):
-  print 'Time for building mesh', time.clock()-t
+  print('Time for building mesh', time.clock()-t)
 t = time.clock()
 
 # create a MeshFem for u and rhs fields of dimension 1 (i.e. a scalar field)
@@ -83,15 +83,15 @@ m.set_region(DIRICHLET_BOUNDARY_NUM2, ftop)
 m.set_region(NEUMANN_BOUNDARY_NUM, fneum)
 
 if (rank == 0):
-  print 'Time for building fem and im', time.clock()-t
+  print('Time for building fem and im', time.clock()-t)
 t = time.clock()
 
 nb_dof = mfu.nbdof()
 if (rank == 0):
-  print 'Nb dof for the main unknown: ', nb_dof
+  print('Nb dof for the main unknown: ', nb_dof)
 
 if (rank == 0):
-  print 'Time for dof numbering', time.clock()-t
+  print('Time for dof numbering', time.clock()-t)
 t = time.clock()
   
 
@@ -103,7 +103,7 @@ F1 = mfrhs.eval('-(2*(x*x+y*y)-2*x-2*y+20*x*x*x)')
 F2 = mfrhs.eval('[y*(y-1)*(2*x-1) + 5*x*x*x*x, x*(x-1)*(2*y-1)]')
 
 if (rank == 0):
-  print 'Time for python interpolation', time.clock()-t
+  print('Time for python interpolation', time.clock()-t)
 t = time.clock()
 
 # model
@@ -149,23 +149,23 @@ else:
                                                'DirichletData')
 
 if (rank == 0):
-  print 'Time for model building', time.clock()-t
+  print('Time for model building', time.clock()-t)
 t = time.clock()
 
 md.nbdof
 nb_dof = md.nbdof()
 if (rank == 0):
-  print 'Nb dof for the model: ', nb_dof
+  print('Nb dof for the model: ', nb_dof)
 
 if (rank == 0):
-  print 'Time for model actualize sizes', time.clock()-t
+  print('Time for model actualize sizes', time.clock()-t)
 t = time.clock()
 
 # assembly of the linear system and solve.
 md.solve()
 
 if (rank == 0):
-  print 'Time for model solve', time.clock()-t
+  print('Time for model solve', time.clock()-t)
 t = time.clock()
 
 # main unknown
@@ -174,11 +174,11 @@ L2error = gf.compute(mfu, U-Ue, 'L2 norm', mim)
 H1error = gf.compute(mfu, U-Ue, 'H1 norm', mim)
 
 if (rank == 0):
-  print 'Error in L2 norm : ', L2error
-  print 'Error in H1 norm : ', H1error
+  print('Error in L2 norm : ', L2error)
+  print('Error in H1 norm : ', H1error)
 
 if (rank == 0):
-  print 'Time for error computation', time.clock()-t
+  print('Time for error computation', time.clock()-t)
 t = time.clock()
 
 
@@ -186,6 +186,6 @@ t = time.clock()
 # if (rank == 0):
 #   mfu.export_to_pos('laplacian.pos', Ue,'Exact solution',
 #                     U,'Computed solution')
-#   print 'You can view the solution with (for example):'
-#   print 'gmsh laplacian.pos'
+#   print('You can view the solution with (for example):')
+#   print('gmsh laplacian.pos')
 
diff --git a/interface/tests/python/demo_plasticity.py 
b/interface/tests/python/demo_plasticity.py
index 97d6e28..c2baa7a 100644
--- a/interface/tests/python/demo_plasticity.py
+++ b/interface/tests/python/demo_plasticity.py
@@ -36,7 +36,7 @@ with_graphics=True
 try:
     import getfem_tvtk
 except:
-    print "\n** Could NOT import getfem_tvtk -- graphical output disabled **\n"
+    print("\n** Could NOT import getfem_tvtk -- graphical output disabled 
**\n")
     import time
     time.sleep(2)
     with_graphics=False
@@ -94,9 +94,9 @@ md.add_Dirichlet_condition_with_multipliers(mim, 'u', mfu, 1)
 F=np.array([[0,-4.],[0, -5.], [0, -4.], [0, 2.], [0, 0]])
 nbstep = F.shape[0]
 
-print 'nbstep:', nbstep
+print('nbstep:', nbstep)
 for step in range(0, nbstep):
-    print 'step %d' % (step,)
+    print('step %d' % (step,))
     md.set_variable('VolumicData', [F[step,0],F[step,1]])
     md.solve('noisy', 'lsearch', 'simplest',  'alpha min', 0.8, 'max_iter', 
100, 'max_res', 1e-6)
     U = md.variable('u')
@@ -111,5 +111,5 @@ for step in range(0, nbstep):
     if with_graphics:
         fig = getfem_tvtk.Figure()
         fig.show(mfu, deformation=U, deformation_scale=1, data=(mfdu,VM))
-        print "Press Q to continue.."
+        print("Press Q to continue..")
         fig.loop()
diff --git a/interface/tests/python/demo_plate.py 
b/interface/tests/python/demo_plate.py
index e6aab9f..d8a26ce 100644
--- a/interface/tests/python/demo_plate.py
+++ b/interface/tests/python/demo_plate.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2004-2017 Yves Renard, Julien Pommier.
@@ -78,9 +78,9 @@ md.add_Dirichlet_condition_with_multipliers(mim, 'u3', mfu3, 
SIMPLE_SUPPORT_BOUN
                                              
 
 
-print 'running solve...'
+print('running solve...')
 md.solve()
-print 'solve done!'
+print('solve done!')
 
 
 u3 = md.variable('u3')
@@ -90,7 +90,7 @@ sl=gf.Slice(('none',), mfu3, 4)
 sl.export_to_vtk('plate.vtk', mfu3, u3, 'Displacement')
 sl.export_to_pos('plate.pos', mfu3, u3, 'Displacement')
 
-print 'You can view the solution with (for example):'
-print 'mayavi2 -d plate.vtk -f WarpScalar -m Surface'
-print 'or'
-print 'gmsh plate.pos'
+print('You can view the solution with (for example):')
+print('mayavi2 -d plate.vtk -f WarpScalar -m Surface')
+print('or')
+print('gmsh plate.pos')
diff --git a/interface/tests/python/demo_static_contact.py 
b/interface/tests/python/demo_static_contact.py
index f4f387a..17e0808 100644
--- a/interface/tests/python/demo_static_contact.py
+++ b/interface/tests/python/demo_static_contact.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2011-2017 Yves Renard.
@@ -243,7 +243,7 @@ elif version == 9: # The integral version, Uzawa on the 
augmented Lagrangian
      (mim_friction, 'u', 'obstacle', 'r', GAMMAC, 2, 'lambda_n')
 
    for ii in range(100):
-      print 'iteration %d' % (ii+1)
+      print('iteration %d' % (ii+1))
       md.solve('max_res', 1E-9, 'max_iter', niter)
       U = md.get('variable', 'u')
       lambda_n_old = lambda_n
@@ -251,7 +251,7 @@ elif version == 9: # The integral version, Uzawa on the 
augmented Lagrangian
       lambda_n = sol[0].transpose()
       md.set_variable('lambda_n', lambda_n)
       difff = max(abs(lambda_n-lambda_n_old))[0]/max(abs(lambda_n))[0]
-      print 'diff : %g' % difff
+      print('diff : %g' % difff)
       if difff < penalty_parameter:
          break
 
@@ -287,7 +287,7 @@ elif version == 14: # The integral version, Uzawa on the 
augmented Lagrangian wi
      (mim_friction, 'u', 'obstacle', 'r', 'friction_coeff', GAMMAC, 2, 
'lambda')
 
    for ii in range(100):
-      print 'iteration %d' % (ii+1)
+      print('iteration %d' % (ii+1))
       md.solve('max_res', 1E-9, 'max_iter', niter)
       U = md.get('variable', 'u')
       lambda_nt_old = lambda_nt
@@ -297,7 +297,7 @@ elif version == 14: # The integral version, Uzawa on the 
augmented Lagrangian wi
       lambda_nt = sol[0].transpose()
       md.set_variable('lambda', lambda_nt)
       difff = max(abs(lambda_nt-lambda_nt_old))[0]/max(abs(lambda_nt))[0]
-      print 'diff : %g' % difff
+      print('diff : %g' % difff)
       if difff < penalty_parameter:
          break
  
@@ -313,7 +313,7 @@ elif version == 15:
      (mim_friction, 'u', 'obstacle', 'r', 'friction_coeff', GAMMAC)
 
 else:
-   print 'Inexistent version'
+   print('Inexistent version')
 
 # Solve the problem
 if not solved:
diff --git a/interface/tests/python/demo_step_by_step.py 
b/interface/tests/python/demo_step_by_step.py
index 9c7f31d..d8347d0 100644
--- a/interface/tests/python/demo_step_by_step.py
+++ b/interface/tests/python/demo_step_by_step.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2004-2017 Julien Pommier.
@@ -33,7 +33,7 @@ mf = gf.MeshFem(m, 1)
 mf.set_fem(gf.Fem('FEM_QK(2,2)'))
 
 # view the expression of its basis functions on the reference convex
-print gf.Fem('FEM_QK(2,2)').poly_str()
+print(gf.Fem('FEM_QK(2,2)').poly_str())
 
 # an exact integration will be used
 mim = gf.MeshIm(m, gf.Integ('IM_GAUSS_PARALLELEPIPED(2,4)'))
diff --git a/interface/tests/python/demo_stokes_3D_tank.py 
b/interface/tests/python/demo_stokes_3D_tank.py
index ab08efb..1567fba 100644
--- a/interface/tests/python/demo_stokes_3D_tank.py
+++ b/interface/tests/python/demo_stokes_3D_tank.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2004-2017 Yves Renard, Julien Pommier.
@@ -22,13 +22,13 @@
 from getfem import *
 from numpy import *
 
-print '3D stokes demonstration on a quadratic mesh -- 512MB needed for the 
solve.'
+print('3D stokes demonstration on a quadratic mesh')
 
 viscosity = 10
 
 
 m=Mesh('import','GiD','../meshes/tank_quadratic_2500.GiD.msh')
-print 'mesh loaded!'
+print('mesh loaded!')
 mfu=MeshFem(m,3) # velocity
 mfulag=MeshFem(m,3)
 mfp=MeshFem(m,1) # pressure
@@ -41,8 +41,8 @@ mfd.set_fem(Fem('FEM_PK(3,2)'))
 mfp.set_fem(Fem('FEM_PK(3,1)'))
 mfe.set_fem(Fem('FEM_PK_DISCONTINUOUS(3,1,0.01)'))
 
-print 'nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
-      (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof())
+print('nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
+      (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof()))
 
 
 P=m.pts()
@@ -89,9 +89,9 @@ md.add_Dirichlet_condition_with_multipliers(mim, 'u', mfu, 2, 
'Dir2data');
 md.add_Dirichlet_condition_with_multipliers(mim, 'u', mfu, 3);
 md.add_Dirichlet_condition_with_multipliers(mim, 'u', mfu, 4);
 
-print 'running solve...'
+print('running solve...')
 md.solve('noisy', 'lsolver','superlu')
-print 'solve done!'
+print('solve done!')
 
 
 U = md.variable('u');
diff --git a/interface/tests/python/demo_stokes_3D_tank_draw.py 
b/interface/tests/python/demo_stokes_3D_tank_draw.py
index c7b3fe1..a6e2e65 100644
--- a/interface/tests/python/demo_stokes_3D_tank_draw.py
+++ b/interface/tests/python/demo_stokes_3D_tank_draw.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2004-2017 Yves Renard, Julien Pommier.
@@ -30,9 +30,9 @@ P = fromfile('tank_3D.P', 'd')
 
 
sl=getfem.Slice(('boundary',('intersection',('planar',+1,[0,0,0],[0,1,0]),('planar',+1,[0,0,0],[1,0,0]))),m,3);
 
-print "importing tvtk.."
+print("importing tvtk..")
 import getfem_tvtk
-print "import done"
+print("import done")
 
 fig = getfem_tvtk.Figure(gui='tvtk')
 
@@ -48,7 +48,7 @@ 
sl=getfem.Slice(('boundary',('intersection',('planar',+1,[0,0,6],[0,0,-1]),
 fig.show(sl, data=(mfp, P), scalar_bar=True, edges=False)
 fig.scalar_range((-40,40));
 
-#print fig.scalar_range()
+#print(fig.scalar_range())
 
 m.set_region(42, m.outer_faces());
 m.region_subtract(42, 3);
diff --git 
a/interface/tests/python/demo_thermo_elasticity_electrical_coupling.py 
b/interface/tests/python/demo_thermo_elasticity_electrical_coupling.py
index 6e580f8..1b00445 100644
--- a/interface/tests/python/demo_thermo_elasticity_electrical_coupling.py
+++ b/interface/tests/python/demo_thermo_elasticity_electrical_coupling.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C)  2015-2017 Yves Renard.
@@ -93,7 +93,7 @@ mo4 = gf.MesherObject('ball', [75., 12.5], 8.)
 mo5 = gf.MesherObject('union', mo2, mo3, mo4)
 mo  = gf.MesherObject('set minus', mo1, mo5)
 
-print 'Mesh generation';
+print('Mesh generation')
 gf.util('trace level', 2)   # No trace for mesh generation
 mesh = gf.Mesh('generate', mo, h, 2)
 
@@ -120,8 +120,8 @@ mesh.region_subtract(BOTTOM_BOUND, HOLE_BOUND)
 
 if (export_mesh):
     mesh.export_to_vtk('mesh.vtk');
-    print ('\nYou can view the mesh for instance with');
-    print ('mayavi2 -d mesh.vtk -f ExtractEdges -m Surface \n');
+    print('\nYou can view the mesh for instance with');
+    print('mayavi2 -d mesh.vtk -f ExtractEdges -m Surface \n');
 
 #
 # Definition of finite elements methods and integration method
@@ -192,15 +192,15 @@ md.add_linear_generic_assembly_brick(mim, 
'beta*(T0-theta)*Trace(Grad_Test_u)')
 #
 if (solve_in_two_steps):
   md.disable_variable('u')
-  print 'First problem with', md.nbdof(), ' dofs'
+  print('First problem with', md.nbdof(), ' dofs')
   md.solve('max_res', 1E-9, 'max_iter', 100, 'noisy')
   md.enable_variable('u')
   md.disable_variable('theta')
   md.disable_variable('V')
-  print 'Second problem with ', md.nbdof(), ' dofs'
+  print('Second problem with ', md.nbdof(), ' dofs')
   md.solve('max_res', 1E-9, 'max_iter', 100, 'noisy')
 else:
-  print 'Global problem with ', md.nbdof(), ' dofs'
+  print('Global problem with ', md.nbdof(), ' dofs')
   md.solve('max_res', 1E-9, 'max_iter', 100, 'noisy')
 
 
@@ -214,11 +214,11 @@ VM = 
md.compute_isotropic_linearized_Von_Mises_or_Tresca('u', 'clambdastar', 'cm
 CO = np.reshape(md.interpolation('-'+sigmaeps+'*Grad_V', mfvm), (2, 
mfvm.nbdof()), 'F')
 
 mfvm.export_to_vtk('displacement_with_von_mises.vtk', mfvm,  VM, 'Von Mises 
Stresses', mfu, U, 'Displacements')
-print ('You can view solutions with for instance:\nmayavi2 -d 
displacement_with_von_mises.vtk -f WarpVector -m Surface')
+print('You can view solutions with for instance:\nmayavi2 -d 
displacement_with_von_mises.vtk -f WarpVector -m Surface')
 mft.export_to_vtk('temperature.vtk', mft, THETA, 'Temperature')
-print ('mayavi2 -d temperature.vtk -f WarpScalar -m Surface')
+print('mayavi2 -d temperature.vtk -f WarpScalar -m Surface')
 mft.export_to_vtk('electric_potential.vtk', mft, V, 'Electric potential')
-print ('mayavi2 -d electric_potential.vtk -f WarpScalar -m Surface')
+print('mayavi2 -d electric_potential.vtk -f WarpScalar -m Surface')
 
 
 
diff --git a/interface/tests/python/demo_tripod.py 
b/interface/tests/python/demo_tripod.py
index b9e4d35..158911a 100644
--- a/interface/tests/python/demo_tripod.py
+++ b/interface/tests/python/demo_tripod.py
@@ -35,14 +35,14 @@ with_graphics=True
 try:
     import getfem_tvtk
 except:
-    print "\n** Could NOT import getfem_tvtk -- graphical output disabled **\n"
+    print("\n** Could NOT import getfem_tvtk -- graphical output disabled 
**\n")
     import time
     time.sleep(2)
     with_graphics=False
 
 
 m=gf.Mesh('import','gid','../meshes/tripod.GiD.msh')
-print 'done!'
+print('done!')
 mfu=gf.MeshFem(m,3) # displacement
 mfp=gf.MeshFem(m,1) # pressure
 mfd=gf.MeshFem(m,1) # data
@@ -55,11 +55,11 @@ mfu.set_fem(gf.Fem('FEM_PK(3,%d)' % (degree,)))
 mfd.set_fem(gf.Fem('FEM_PK(3,0)'))
 mfp.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,0)'))
 
-print 'nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
-      (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof())
+print('nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
+      (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof()))
 
 P=m.pts()
-print 'test', P[1,:]
+print('test', P[1,:])
 ctop=(abs(P[1,:] - 13) < 1e-6)
 cbot=(abs(P[1,:] + 10) < 1e-6)
 pidtop=np.compress(ctop, range(0, m.nbpts()))
@@ -106,10 +106,10 @@ md.add_source_term_brick(mim, 'u', 'VolumicData');
 # Attach the tripod to the ground
 md.add_Dirichlet_condition_with_multipliers(mim, 'u', mfu, 2);
 
-print 'running solve...'
+print('running solve...')
 md.solve('noisy', 'max iter', 1);
 U = md.variable('u');
-print 'solve done!'
+print('solve done!')
 
 
 mfdu=gf.MeshFem(m,1)
@@ -122,7 +122,7 @@ else:
 # post-processing
 sl=gf.Slice(('boundary',), mfu, degree)
 
-print 'Von Mises range: ', VM.min(), VM.max()
+print('Von Mises range: ', VM.min(), VM.max())
 
 # export results to VTK
 sl.export_to_vtk('tripod.vtk', 'ascii', mfdu,  VM, 'Von Mises Stress', mfu, U, 
'Displacement')
@@ -130,10 +130,10 @@ sl.export_to_pos('tripod.pos', mfdu, VM, 'Von Mises 
Stress', mfu, U, 'Displaceme
 
 gf.memstats()
 
-print 'You can view the tripod with (for example) mayavi:'
-print 'mayavi2 -d tripod.vtk -f WarpVector -m Surface'
-print 'or'
-print 'gmsh tripod.pos'
+print('You can view the tripod with (for example) mayavi:')
+print('mayavi2 -d tripod.vtk -f WarpVector -m Surface')
+print('or')
+print('gmsh tripod.pos')
 
 # mfu.save('tripod.mf', 'with_mesh')
 # U.tofile('tripod.U')
@@ -143,6 +143,6 @@ print 'gmsh tripod.pos'
 if with_graphics:
   fig = getfem_tvtk.Figure()
   fig.show(mfu, deformation=U, data=(mfdu,VM), deformation_scale='20%')
-  print "Press Q to continue.."
+  print("Press Q to continue..")
   fig.set_colormap('tripod')
   fig.loop()
diff --git a/interface/tests/python/demo_tripod_alt.py 
b/interface/tests/python/demo_tripod_alt.py
index c28b0c3..50ca518 100644
--- a/interface/tests/python/demo_tripod_alt.py
+++ b/interface/tests/python/demo_tripod_alt.py
@@ -31,9 +31,9 @@
 from getfem import *
 from numpy import *
 
-print 'importing the mesh..',
+print('importing the mesh..',)
 m=Mesh('import','gid','../meshes/tripod.GiD.msh')
-print 'done!'
+print('done!')
 mfu=MeshFem(m,3)
 mfd=MeshFem(m,1)
 mfe=MeshFem(m,1)
@@ -43,8 +43,8 @@ mfu.set_fem(Fem('FEM_PK(3,%d)' % (degree,)));
 mfe.set_fem(Fem('FEM_PK_DISCONTINUOUS(3,%d,0.01)' % (degree,)))
 mfd.set_fem(Fem('FEM_PK(3,0)'))
 
-print 'nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
-      (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof())
+print('nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
+      (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof()))
 
 P=m.pts()
 
@@ -80,11 +80,11 @@ KK=Nt*K*N
 FF=Nt*F
 
 # solve ...
-print "preconditioner.."
+print("preconditioner..")
 P=Precond('ildlt',KK)
-print "solving...",
+print("solving..."),
 UU=linsolve_cg(KK,FF,P)
-print "done!"
+print("done!")
 U=N*UU+U0
 
 # post-processing
@@ -101,7 +101,7 @@ for i in range(0, DU.shape[2]):
   Sigma[:,:,i]=E
   VM[i] = sum(E.ravel()**2) - (1./3.)*sum(diagonal(E))**2
 
-print 'Von Mises range: ', VM.min(), VM.max()
+print('Von Mises range: ', VM.min(), VM.max())
 
 # export results to VTK you can use
 # i.e. with  "mayavi2 -d tripod.vtk -f WarpScalar -m Surface"
@@ -118,7 +118,7 @@ sl.export_to_vtk('tripod_ev.vtk', mfu, U, 'Displacement', 
SigmaSL, 'stress')
 # export to Gmsh POS
 sl.export_to_pos('tripod.pos', mfe, VM, 'Von Mises Stress', mfu, U, 
'Displacement')
 
-print 'You can view the tripod with (for example) mayavi:'
-print 'mayavi2 -d tripod.vtk -f WarpScalar -m Surface'
-print 'or'
-print 'gmsh tripod.pos'
+print('You can view the tripod with (for example) mayavi:')
+print('mayavi2 -d tripod.vtk -f WarpScalar -m Surface')
+print('or')
+print('gmsh tripod.pos')
diff --git a/interface/tests/python/demo_wave.py 
b/interface/tests/python/demo_wave.py
index 36e7d2a..ec76aa9 100644
--- a/interface/tests/python/demo_wave.py
+++ b/interface/tests/python/demo_wave.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2004-2017 Yves Renard, Julien Pommier.
@@ -30,7 +30,7 @@ from numpy import *
 from getfem import *
 import os
 
-make_check=os.environ.has_key('srcdir');
+make_check=('srcdir' in os.environ);
 
 filename='../meshes/holed_disc_with_quadratic_2D_triangles.msh';
 if (make_check):
@@ -89,5 +89,5 @@ if (not(make_check)):
     sl.export_to_vtk('wave.vtk', mfu, real(U), 'rWave',
                      mfu, imag(U), 'iWave')
 
-    print 'You can view the solution with (for instance):'
-    print 'mayavi2 -d wave.vtk -f WarpScalar -m Surface'
+    print('You can view the solution with (for instance):')
+    print('mayavi2 -d wave.vtk -f WarpScalar -m Surface')
diff --git a/interface/tests/python/demo_wheel_contact.py 
b/interface/tests/python/demo_wheel_contact.py
index 03434f8..0aea7a0 100644
--- a/interface/tests/python/demo_wheel_contact.py
+++ b/interface/tests/python/demo_wheel_contact.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C)  2015-2017 Yves Renard.
@@ -57,7 +57,7 @@ mo1 = gf.MesherObject('ball', [0., 15.], 15.)
 mo2 = gf.MesherObject('ball', [0., 15.], 8.)
 mo3 = gf.MesherObject('set minus', mo1, mo2)
 
-print ('Meshes generation')
+print('Meshes generation')
 mesh1 = gf.Mesh('generate', mo3, h, 2)
 mesh2 = 
gf.Mesh('import','structured','GT="GT_PK(2,1)";SIZES=[30,10];NOISED=0;NSUBDIV=[%d,%d];'
 % (int(30/h)+1, int(10/h)+1));
 mesh2.translate([-15.,-10.])
@@ -66,8 +66,8 @@ mesh2.translate([-15.,-10.])
 if (export_mesh):
   mesh1.export_to_vtk('mesh1.vtk')
   mesh2.export_to_vtk('mesh2.vtk')
-  print ('\nYou can view the meshes for instance with')
-  print ('mayavi2  -d mesh1.vtk -f ExtractEdges -m Surface -d mesh2.vtk -f 
ExtractEdges -m Surface \n')
+  print('\nYou can view the meshes for instance with')
+  print('mayavi2  -d mesh1.vtk -f ExtractEdges -m Surface -d mesh2.vtk -f 
ExtractEdges -m Surface \n')
 
 
 #
@@ -147,11 +147,11 @@ else:
 # Model solve
 #
 
-print 'Solve problem with ', md.nbdof(), ' dofs'
+print('Solve problem with ', md.nbdof(), ' dofs')
 md.solve('max_res', 1E-9, 'max_iter', 40, 'noisy') # , 'lsearch', 'simplest',  
'alpha min', 0.8)
 if not(Dirichlet_version):
-  print 'alpha_D = ', md.variable('alpha_D')[0]
-# print 'Contact multiplier ', md.variable('lambda1')
+  print('alpha_D = ', md.variable('alpha_D')[0])
+# print('Contact multiplier ', md.variable('lambda1'))
 
 #
 # Solution export
@@ -164,5 +164,5 @@ VM2 = 
md.compute_isotropic_linearized_Von_Mises_or_Tresca('u2', 'clambdastar', '
 mfvm1.export_to_vtk('displacement_with_von_mises1.vtk', mfvm1,  VM1, 'Von 
Mises Stresses', mfu1, U1, 'Displacements')
 
 mfvm2.export_to_vtk('displacement_with_von_mises2.vtk', mfvm2,  VM2, 'Von 
Mises Stresses', mfu2, U2, 'Displacements')
-print ('You can view solutions with for instance:\nmayavi2 -d 
displacement_with_von_mises1.vtk -f WarpVector -m Surface -d 
displacement_with_von_mises2.vtk -f WarpVector -m Surface')
+print('You can view solutions with for instance:\nmayavi2 -d 
displacement_with_von_mises1.vtk -f WarpVector -m Surface -d 
displacement_with_von_mises2.vtk -f WarpVector -m Surface')
 
diff --git a/interface/tests/python/getfem_tvtk.py 
b/interface/tests/python/getfem_tvtk.py
index fa3b51d..9351738 100644
--- a/interface/tests/python/getfem_tvtk.py
+++ b/interface/tests/python/getfem_tvtk.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: UTF8 -*-
+# -*- coding: utf-8 -*-
 # Python GetFEM++ interface
 #
 # Copyright (C) 2004-2017 Yves Renard, Julien Pommier.
@@ -32,8 +32,8 @@
 try:
     from tvtk.api import tvtk
 except:
-    print "\n\n** Could not load tvtk. Did you install it ?\n"
-    print "   ( https://svn.enthought.com/enthought/wiki/TVTK ) **\n\n"
+    print("\n\n** Could not load tvtk. Did you install it ?\n")
+    print("   ( https://svn.enthought.com/enthought/wiki/TVTK ) **\n\n")
     raise
 
 import os
@@ -216,7 +216,7 @@ class FigureItem:
                 scale = float(scale[:-1]) * 0.01 * a/b;
         P=P + scale * deform
         self.sl.set_pts(P)
-        #print "deformation!", repr(mf), U.size(), repr(self.sl), 
"\nDEFORM=",self.deform,"\n"
+        #print("deformation!", repr(mf), U.size(), repr(self.sl), 
"\nDEFORM=",self.deform,"\n")
         sys.stdout.flush()
 
 
@@ -510,7 +510,7 @@ class Figure:
 ##    E1.transpose()
 ##    edges=tvtk.PolyData(points=array(Pe),polys=array(E1))
 
-##    print mesh.get()
+##    print(mesh.get())
 
 
 ##    #data = array([[0,0,0,10], [1,0,0,20],
@@ -555,7 +555,7 @@ class Figure:
 ##    # across the entire range of colors
 ##    mapper = tvtk.PolyDataMapper(input=mesh);
 ##    mapper_edges = tvtk.PolyDataMapper(input=edges);
-##    print mapper
+##    print(mapper)
 
 ##    #mapper = tvtk.PolyDataMapper(input=mesh)
 ##    #mapper.scalar_range = min(temperature), max(temperature)
@@ -588,7 +588,7 @@ class Figure:
 ##    gui.start_event_loop()
 
 
-##    print "finished!"
+##    print("finished!")
 
 
 ##    #f=mlab.figure()
diff --git a/m4/ac_python_devel.m4 b/m4/ac_python_devel.m4
index d6495be..acfb21e 100644
--- a/m4/ac_python_devel.m4
+++ b/m4/ac_python_devel.m4
@@ -51,8 +51,8 @@ AC_DEFUN([AC_PYTHON_DEVEL],[
        #
        AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
        ac_supports_python_ver=`$PYTHON -c "import sys, string; \
-               ver = string.split(sys.version)[[0]]; \
-               print int(ver >= '2.1.0')"`
+               ver =(sys.version.split())[[0]]; \
+               print(int(ver >= '2.1.0'))"`
        if test "$ac_supports_python_ver" != "1"; then
                if test -z "$PYTHON_NOVERSIONCHECK"; then
                        AC_MSG_RESULT([no])
@@ -78,8 +78,8 @@ to something else than an empty string.
        if test -n "$1"; then
                AC_MSG_CHECKING([for a version of Python $1])
                ac_supports_python_ver=`$PYTHON -c "import sys, string; \
-                       ver = string.split(sys.version)[[0]]; \
-                       print ver $1"`
+                       ver = (sys.version.split())[[0]]; \
+                       print(ver $1)"`
                if test "$ac_supports_python_ver" = "True"; then
                   AC_MSG_RESULT([yes])
                else
@@ -113,7 +113,7 @@ $ac_distutils_result])
        AC_MSG_CHECKING([for Python include path])
        if test -z "$PYTHON_CPPFLAGS"; then
                python_path=`$PYTHON -c "import distutils.sysconfig; \
-                       print distutils.sysconfig.get_python_inc();"`
+                       print(distutils.sysconfig.get_python_inc());"`
                if test -n "${python_path}"; then
                        python_path="-I$python_path"
                fi
@@ -130,21 +130,20 @@ $ac_distutils_result])
                # (makes two attempts to ensure we've got a version number
                # from the interpreter)
                py_version=`$PYTHON -c "from distutils.sysconfig import *; \
-                       from string import join; \
-                       print join(get_config_vars('VERSION'))"`
+                       import string; \
+                       print(get_config_vars('VERSION')[[0]])"`
                if test "$py_version" == "[None]"; then
                        if test -n "$PYTHON_VERSION"; then
                                py_version=$PYTHON_VERSION
                        else
                                py_version=`$PYTHON -c "import sys; \
-                                       print sys.version[[:3]]"`
+                                       print(sys.version[[:3]])"`
                        fi
                fi
 
                PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
-                       from string import join; \
-                       print '-L' + get_python_lib(0,1), \
-                       '-lpython';"`$py_version
+                       print('-L' + get_python_lib(0,1), \
+                       '-lpython');"`$py_version
        fi              
        AC_MSG_RESULT([$PYTHON_LDFLAGS])
        AC_SUBST([PYTHON_LDFLAGS])
@@ -155,7 +154,7 @@ $ac_distutils_result])
        AC_MSG_CHECKING([for Python site-packages path])
        if test -z "$PYTHON_SITE_PKG"; then
                PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
-                       print distutils.sysconfig.get_python_lib(0,0);"`
+                       print(distutils.sysconfig.get_python_lib(0,0));"`
        fi
        AC_MSG_RESULT([$PYTHON_SITE_PKG])
        AC_SUBST([PYTHON_SITE_PKG])
@@ -167,7 +166,7 @@ $ac_distutils_result])
        if test -z "$PYTHON_EXTRA_LIBS"; then
           PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
                 conf = distutils.sysconfig.get_config_var; \
-                print conf('LOCALMODLIBS'), conf('LIBS')"`
+                print(conf('LOCALMODLIBS'), conf('LIBS'))"`
        fi
        AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
        AC_SUBST(PYTHON_EXTRA_LIBS)
@@ -179,7 +178,7 @@ $ac_distutils_result])
        if test -z "$PYTHON_EXTRA_LDFLAGS"; then
                PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
                        conf = distutils.sysconfig.get_config_var; \
-                       print conf('LINKFORSHARED')"`
+                       print(conf('LINKFORSHARED'))"`
        fi
        AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
        AC_SUBST(PYTHON_EXTRA_LDFLAGS)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]