Last active
March 14, 2017 18:55
-
-
Save DrDougPhD/be70ed85aa6fc2f96bfba911ecce9cac to your computer and use it in GitHub Desktop.
This Python function is useful for argparse declarations that receive directories that both need to be verified existing and converted to absolute paths.
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
''' | |
Copyright 2017 Doug McGeehan under the GPLv3. | |
''' | |
import os | |
def verified_absolute_path(path): | |
abs_path = os.path.abspath(path) | |
assert os.path.isdir(abs_path),\ | |
'No directory exists at "{}"'.format(abs_path) | |
return abs_path | |
# Demonstrate the script | |
if __name__ == '__main__': | |
current_dir = '.' | |
abs_path = verified_absolute_path(current_dir) | |
print('Converted {0} to {1}'.format(current_dir, abs_path)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment