From 6f6467ac9cc71598c2946b7e84abcd3adea98528 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Thu, 9 Jun 2016 14:39:34 +0000 Subject: Catch if file does not exist git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1267 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: b5490aa143b0303da6a92fcc7f7df7656101592a --- .../cubical_complex_from_perseus_file_example.py | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/cython/example/cubical_complex_from_perseus_file_example.py b/src/cython/example/cubical_complex_from_perseus_file_example.py index 9fc083ff..23f7ece6 100755 --- a/src/cython/example/cubical_complex_from_perseus_file_example.py +++ b/src/cython/example/cubical_complex_from_perseus_file_example.py @@ -4,7 +4,7 @@ import gudhi import numpy import argparse import operator - +import os """This file is part of the Gudhi Library. The Gudhi library (Geometric Understanding in Higher Dimensions) is a generic C++ @@ -36,18 +36,21 @@ parser = argparse.ArgumentParser(description='Cubical complex from a perseus' 'file style name.', epilog='Example: ' './cubical_complex_from_perseus_file_example.py' - '../data/bitmap/CubicalTwoSphere.txt') -parser.add_argument('perseus_file', type=str, required=True, - help='Perseus file style name') + ' -f ../data/bitmap/CubicalTwoSphere.txt') + +parser.add_argument("-f", "--file", type=str, required=True) args = parser.parse_args() -print("#####################################################################") -print("CubicalComplex creation") -cubical_complex = gudhi.CubicalComplex(perseus_file=args.perseus_file) +if os.access(args.file, os.R_OK): + print("#####################################################################") + print("CubicalComplex creation") + cubical_complex = gudhi.CubicalComplex(perseus_file=args.file) -print("persistence(homology_coeff_field=2, min_persistence=0)=") -print(cubical_complex.persistence(homology_coeff_field=2, min_persistence=0)) + print("persistence(homology_coeff_field=2, min_persistence=0)=") + print(cubical_complex.persistence(homology_coeff_field=2, min_persistence=0)) -print("betti_numbers()=") -print(cubical_complex.betti_numbers()) \ No newline at end of file + print("betti_numbers()=") + print(cubical_complex.betti_numbers()) +else: + print(args.file, "is unreachable") -- cgit v1.2.3