From 45254249e65f5255389c63f60fe0f7da73883ea4 Mon Sep 17 00:00:00 2001 From: Gilles DAVID Date: Wed, 24 May 2017 13:33:30 +0200 Subject: [PATCH] optparse => argparse --- doc/pyplots/process_vtk.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) 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) -- 2.39.2