From: Gilles DAVID Date: Wed, 24 May 2017 10:10:50 +0000 (+0200) Subject: Porting Python 3 X-Git-Tag: V9_0_0~5^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=abc23ff8955bd6143483170aeee45538ad79da72;p=modules%2Fmed.git Porting Python 3 --- diff --git a/doc/tut/addfields/operations.py b/doc/tut/addfields/operations.py index efd59f76e..de5ac14cc 100644 --- a/doc/tut/addfields/operations.py +++ b/doc/tut/addfields/operations.py @@ -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 diff --git a/doc/tut/medcoupling/pyfunctions/functions.py b/doc/tut/medcoupling/pyfunctions/functions.py index a39d0934c..75a8f0f8d 100755 --- a/doc/tut/medcoupling/pyfunctions/functions.py +++ b/doc/tut/medcoupling/pyfunctions/functions.py @@ -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 diff --git a/doc/tut/medcoupling/pyfunctions/lagrange.py b/doc/tut/medcoupling/pyfunctions/lagrange.py index 3913b1c0e..f92e7e5c9 100755 --- a/doc/tut/medcoupling/pyfunctions/lagrange.py +++ b/doc/tut/medcoupling/pyfunctions/lagrange.py @@ -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 diff --git a/doc/tut/medcoupling/pyfunctions/plotter.py b/doc/tut/medcoupling/pyfunctions/plotter.py index 7c52b7587..83ef658dd 100644 --- a/doc/tut/medcoupling/pyfunctions/plotter.py +++ b/doc/tut/medcoupling/pyfunctions/plotter.py @@ -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 diff --git a/doc/tut/medcoupling/testmed_gendata.py b/doc/tut/medcoupling/testmed_gendata.py index 1e0d480e4..e3bc9daab 100755 --- a/doc/tut/medcoupling/testmed_gendata.py +++ b/doc/tut/medcoupling/testmed_gendata.py @@ -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 diff --git a/doc/tut/medcoupling/testmed_lena.py b/doc/tut/medcoupling/testmed_lena.py index 5b5e68610..4054e08f5 100755 --- a/doc/tut/medcoupling/testmed_lena.py +++ b/doc/tut/medcoupling/testmed_lena.py @@ -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 diff --git a/doc/tut/medcoupling/testmed_simple.py b/doc/tut/medcoupling/testmed_simple.py index fa3f79d5f..e2d202cab 100755 --- a/doc/tut/medcoupling/testmed_simple.py +++ b/doc/tut/medcoupling/testmed_simple.py @@ -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 diff --git a/doc/tut/medloader/cmesh.py b/doc/tut/medloader/cmesh.py index 447176ba0..e82cca3c4 100644 --- a/doc/tut/medloader/cmesh.py +++ b/doc/tut/medloader/cmesh.py @@ -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 diff --git a/doc/tut/medloader/explore.py b/doc/tut/medloader/explore.py index 7241c1a1a..c098c1f3b 100644 --- a/doc/tut/medloader/explore.py +++ b/doc/tut/medloader/explore.py @@ -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 diff --git a/doc/tut/medloader/manage.py b/doc/tut/medloader/manage.py index b163ba042..16c27206b 100644 --- a/doc/tut/medloader/manage.py +++ b/doc/tut/medloader/manage.py @@ -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 diff --git a/doc/tut/medloader/tutorial.py b/doc/tut/medloader/tutorial.py index 14955e3ac..2844ca685 100644 --- a/doc/tut/medloader/tutorial.py +++ b/doc/tut/medloader/tutorial.py @@ -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 diff --git a/src/MEDCalc/cmp/test_medcalc_components.py b/src/MEDCalc/cmp/test_medcalc_components.py index 2bb8204c2..e3e3ef005 100644 --- a/src/MEDCalc/cmp/test_medcalc_components.py +++ b/src/MEDCalc/cmp/test_medcalc_components.py @@ -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 diff --git a/src/MEDCalc/exe/image2med/image2med.py b/src/MEDCalc/exe/image2med/image2med.py index defd7c8f1..70d760d05 100755 --- a/src/MEDCalc/exe/image2med/image2med.py +++ b/src/MEDCalc/exe/image2med/image2med.py @@ -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 @@ -20,28 +19,28 @@ # # 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