diff --git a/xfel_calibrate/calibrate.py b/xfel_calibrate/calibrate.py index b865c1384e460b8a4b955dd4cc203e8db2cc3c1a..52470a648e878ae35f6590d874bfd41639f344a3 100755 --- a/xfel_calibrate/calibrate.py +++ b/xfel_calibrate/calibrate.py @@ -101,6 +101,7 @@ def make_intelli_list(ltype): """ class IntelliListAction(argparse.Action): + element_type = ltype def __init__(self, *args, **kwargs): super(IntelliListAction, self).__init__(*args, **kwargs) @@ -109,24 +110,22 @@ def make_intelli_list(ltype): parsed_values = [] values = ",".join(values) - try: - if isinstance(values, str): - for rcomp in values.split(","): - if "-" in rcomp: - start, end = rcomp.split("-") - parsed_values += list(range(int(start), int(end))) - else: - parsed_values += [int(rcomp)] - elif isinstance(values, (list, tuple)): - parsed_values = values - else: - parsed_values = [values, ] - except Exception as e: - print('ERROR:', e) - parsed_values = [self.ltype(p) for p in parsed_values] + if isinstance(values, str): + for rcomp in values.split(","): + if "-" in rcomp: + start, end = rcomp.split("-") + parsed_values += list(range(int(start), int(end))) + else: + parsed_values += [int(rcomp)] + elif isinstance(values, (list, tuple)): + parsed_values = values + else: + parsed_values = [values, ] + + parsed_values = [self.element_type(p) for p in parsed_values] print("Parsed input {} to {}".format(values, parsed_values)) setattr(namespace, self.dest, parsed_values) - IntelliListAction.ltype = ltype + return IntelliListAction