From: Gilles DAVID Date: Wed, 24 May 2017 11:33:30 +0000 (+0200) Subject: optparse => argparse X-Git-Tag: V9_0_0~1^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=45254249e65f5255389c63f60fe0f7da73883ea4;p=modules%2Fhexablock.git optparse => argparse --- diff --git a/doc/pyplots/process_vtk.py b/doc/pyplots/process_vtk.py index 22bbb01..cff68a1 100755 --- a/doc/pyplots/process_vtk.py +++ b/doc/pyplots/process_vtk.py @@ -18,7 +18,7 @@ # import sys import os -from optparse import OptionParser +from argparse import ArgumentParser def process (file_name): """ @@ -27,12 +27,12 @@ def process (file_name): """ wr_data = "" - with open(file_name, 'r') as f: + with open(file_name, 'r', encoding='utf8') as f: read_data = f.read() wr_data = read_data.replace(',', '.') pass - with open(file_name, 'w') as f: + with open(file_name, 'w', encoding='utf8') as f: f.write(wr_data) pass @@ -40,15 +40,11 @@ def process (file_name): if __name__ == '__main__': - usage = "usage: %prog file_name" - parser = OptionParser(usage=usage) - (options, args) = parser.parse_args() - - if len(args) != 1: - print(usage) - sys.exit(1) + parser = ArgumentParser() + parser.add_argument('file_name', help='Nom du fichier vtk dans $TMP') + args = parser.parse_args() - file_name = os.path.join(os.environ['TMP'], args[0]) + file_name = os.path.join(os.environ['TMP'], args.file_name) print(file_name) process(file_name)