def parse_limits(limits): if not limits: return [None, None] limits = limits.strip() if limits[0] == '-': return [None, int(limits[1:])] elif limits[-1] == '-': return [int(limits[:-1]), None] limits = limits.split("-") if len(limits) != 2: print("unknown limits: " + str(limits) + " - using no limits") return [None, None] try: return [int(x) for x in limits] except ValueError as exp: print(exp + " - using no limits") return [None, None]