Salome HOME
Porting Python 3
authorGilles DAVID <gilles-g.david@edf.fr>
Wed, 24 May 2017 10:10:50 +0000 (12:10 +0200)
committerGilles DAVID <gilles-g.david@edf.fr>
Wed, 24 May 2017 10:10:50 +0000 (12:10 +0200)
13 files changed:
doc/tut/addfields/operations.py
doc/tut/medcoupling/pyfunctions/functions.py
doc/tut/medcoupling/pyfunctions/lagrange.py
doc/tut/medcoupling/pyfunctions/plotter.py
doc/tut/medcoupling/testmed_gendata.py
doc/tut/medcoupling/testmed_lena.py
doc/tut/medcoupling/testmed_simple.py
doc/tut/medloader/cmesh.py
doc/tut/medloader/explore.py
doc/tut/medloader/manage.py
doc/tut/medloader/tutorial.py
src/MEDCalc/cmp/test_medcalc_components.py
src/MEDCalc/exe/image2med/image2med.py

index efd59f76ec621d720eb03f36c6cfe114a967ad53..de5ac14ccc59084a5d858c426cb948ad8e757962 100644 (file)
@@ -1,5 +1,4 @@
-#!/usr/bin/env python
-#  -*- coding: iso-8859-1 -*-
+#!/usr/bin/env python3
 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
index a39d0934c892f30bcc7ed2076c2cc3a25a884d48..75a8f0f8d5ee7fa43c42fbd743d342d98c41734f 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
index 3913b1c0e920ddfccdafa122099f83b0b9181caf..f92e7e5c9173cf3e128f569c9d687f1a6fcdad8b 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
@@ -60,7 +60,7 @@ def points_usingarray(arrX,arrY):
 def sortdict(points):
     # Sort this dictionary by keys and returns 2 lists, the list of X
     # and the list of Y, the whole ordered by X
-    keys = sorted(list(points.keys()))
+    keys = sorted(points.keys())
     return keys, [points[key] for key in keys]
 
 import pylab
index 7c52b758714b29598f4223335bea688711943206..83ef658ddce2d98b07f1559bc84a88cb8fb045bc 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
index 1e0d480e404ace4c31c7efcee44b4e6a9683df67..e3bc9daaba80ceee48f99239eb0856ed78a801f6 100755 (executable)
@@ -1,5 +1,4 @@
-#!/usr/bin/env python
-#  -*- coding: iso-8859-1 -*-
+#!/usr/bin/env python3
 # Copyright (C) 2011-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
@@ -212,7 +211,7 @@ def f1(x,y):
 
 # ... but also a more sophisticated callable object, for example to
 # defines some parameters
-class Function(object):
+class Function:
     def __init__(self, sizeX, sizeY, param):
         self.sizeX = sizeX
         self.sizeY = sizeY
index 5b5e686107a979d96e924850d185b7a6b7b8223f..4054e08f5e8b673f1b247607cbfdc937a6a06ef5 100755 (executable)
@@ -1,5 +1,4 @@
-#!/usr/bin/env python
-#  -*- coding: iso-8859-1 -*-
+#!/usr/bin/env python3
 # Copyright (C) 2011-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
@@ -24,6 +23,8 @@
 # as a field in a med file.
 # (gboulant - 27/06/2011)
 
+import os
+
 import MEDCoupling as MC
 import MEDLoader as ML
 
@@ -37,7 +38,8 @@ import scipy, numpy
 #image = scipy.lena()
 # We could either read a real image using the PIL python package.
 from scipy.misc import pilutil
-image = pilutil.imread("images/avatar.png",True)
+CURDIR = os.path.dirname(__file__)
+image = pilutil.imread(os.path.join(CURDIR, "images", "avatar.png"),True)
 
 
 #from PIL import Image
index fa3f79d5f2ed39323d509d7cfba8b71fc8a760c7..e2d202cab1e91a202c3909bcf130bc727336073a 100755 (executable)
@@ -1,5 +1,4 @@
-#!/usr/bin/env python
-#  -*- coding: iso-8859-1 -*-
+#!/usr/bin/env python3
 # Copyright (C) 2011-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
index 447176ba0b60eb2b7caaa68dc436797dadc8b973..e82cca3c422b04fa169befe714a9c55305156d12 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
index 7241c1a1a47655cd4f50764010517a6199ae492a..c098c1f3bb491465ec5922a722f720735f971638 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
index b163ba0426cc5d235fa970ef4df53a10088cdd88..16c27206b480eaf4ddfe47823b96c4f2797d7617 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
@@ -81,14 +81,14 @@ for meshName in meshNames:
 print(list(fieldTree.keys()))
 
 # _T3A
-for meshName in list(fieldTree.keys()):
+for meshName in fieldTree:
     print("%s"%meshName)
-    for fieldName in list(fieldTree[meshName].keys()):
+    for fieldName in fieldTree[meshName]:
         print("  %s"%fieldName)
-        for fieldType in list(fieldTree[meshName][fieldName].keys()):
+        for fieldType in fieldTree[meshName][fieldName]:
             print("    %s"%fieldType)
-            for itNumber in list(fieldTree[meshName][fieldName][fieldType].keys()):
-                for itOrder in list(fieldTree[meshName][fieldName][fieldType][itNumber].keys()):
+            for itNumber in fieldTree[meshName][fieldName][fieldType]:
+                for itOrder in fieldTree[meshName][fieldName][fieldType][itNumber]:
                     print("      (%s,%s)"%(itNumber,itOrder))
                     print(fieldTree[meshName][fieldName][fieldType][itNumber][itOrder])
 # _T3B
index 14955e3ac0405707a6d8704575753d52c80891d9..2844ca685bed69806fce834bd0a66a2cd30d2276 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Copyright (C) 2012-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
index 2bb8204c233a2db5520fccbc23295c420bb7bb8e..e3e3ef00597562503aa872f2e218d9c724fee383 100644 (file)
@@ -1,5 +1,4 @@
-#!/usr/bin/env python
-#  -*- coding: iso-8859-1 -*-
+#!/usr/bin/env python3
 # Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
index defd7c8f1d1cb913cc82f9a260b6d352647be89e..70d760d05ce8446606ad68c61660c581c8e01b7e 100755 (executable)
@@ -1,5 +1,4 @@
-#!/usr/bin/env python
-#  -*- coding: iso-8859-1 -*-
+#!/usr/bin/env python3
 # Copyright (C) 2011-2016  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 #
 # Author : Guillaume Boulant (EDF) 
 
-from optparse import OptionParser
-parser = OptionParser()
-parser.add_option("-i", "--imagefile", dest="imagefile",
+from argparse import ArgumentParser
+parser = ArgumentParser()
+parser.add_agument("-i", "--imagefile", dest="imagefile",
                   help="image file to convert", metavar="FILE")
-parser.add_option("-m", "--medfile", dest="medfile", default=None,
+parser.add_agument("-m", "--medfile", dest="medfile", default=None,
                   help="output med file", metavar="FILE")
-(options, args) = parser.parse_args()
+args = parser.parse_args()
 
 import sys, os
-if options.imagefile is None:
+if args.imagefile is None:
     print("The image file must be specified")
     sys.exit()
-imagefile = options.imagefile
+imagefile = args.imagefile
 if not os.path.exists(imagefile):
     print("The image file %s does not exists"%imagefile)
     sys.exit()
 
-if options.medfile is None:
+if args.medfile is None:
     basename = os.path.basename(imagefile)
     medfile = basename[0:len(basename)-3] + "med"
 else:
-    medfile = options.medfile
+    medfile = args.medfile
 
 print("Convert image file %s to a med field saved in %s"%(imagefile,medfile))
 from xmedimages import FieldBuilder