Last active
March 30, 2016 07:58
-
-
Save etam/075c0851a38919fe9bcf to your computer and use it in GitHub Desktop.
relpath
This file contains 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
#!/usr/bin/env python3 | |
import argparse | |
import os.path | |
import sys | |
def parse_args(argv): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('path') | |
return parser.parse_args(argv) | |
def main(argv): | |
args = parse_args(argv[1:]) | |
print(os.path.abspath(args.path)) | |
if __name__ == "__main__": | |
sys.exit(main(sys.argv)) |
This file contains 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
#!/usr/bin/env python3 | |
import argparse | |
import os.path | |
import sys | |
def parse_args(argv): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('path_to') | |
parser.add_argument('path_from', nargs='?', default=os.getcwd()) | |
return parser.parse_args(argv) | |
def main(argv): | |
args = parse_args(argv[1:]) | |
print(os.path.relpath(args.path_to, args.path_from)) | |
if __name__ == "__main__": | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment