-
-
Save adzhurinskij/3e978bb7e160635c79c297ae8c3ba13c to your computer and use it in GitHub Desktop.
Convert paths to full paths (argparse)
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
class FullPaths(argparse.Action): | |
"""Expand user- and relative-paths""" | |
def __call__(self, parser, namespace, values, option_string=None): | |
setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values))) | |
def get_args(): | |
parser = argparse.ArgumentParser(description='Something smart here') | |
parser.add_argument('my_conf', help='The configuration file for the db', action = FullPaths) | |
return parser.parse_args() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment