Created
February 9, 2015 05:47
-
-
Save devanlai/e4f2b55006df10e62234 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def slice_arg(string): | |
try: | |
if ":" in string: | |
parts = string.split(":") | |
args = [] | |
for part in parts: | |
if not part.strip(): | |
args.append(None) | |
else: | |
args.append(int(part)) | |
return slice(*args) | |
else: | |
index = int(string) | |
return slice(index, index+1) | |
except ValueError: | |
raise argparse.ArgumentTypeError("{} is not a valid slice".format(string)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment