Created
November 22, 2022 15:03
-
-
Save st4lk/195ec0e4eba45cc6fa7e704b6f6f3a2e to your computer and use it in GitHub Desktop.
python argparse example
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
import argparse | |
parser = argparse.ArgumentParser(description='Argparse example command') | |
parser.add_argument('just_string', help='Positional required string argument') | |
parser.add_argument( | |
'--flag', action='store_true', help='Not required boolean argument with default value', | |
) | |
parser.add_argument( | |
'--value', type=str, default='ok', help='Not required string argument with default value', | |
) | |
parser.add_argument( | |
'--ids', nargs='+', default=['1', '2'], help='List of ids: "--ids 1 2 3', | |
) | |
parser.add_argument( | |
'--csv_file', type=str, help='Path to csv, probably you want ergeon/calc/data/values.csv', | |
) | |
# parser.add_argument( | |
# nargs='+', dest='keys', help='Any number of args without name, at least one is required', | |
# ) | |
if __name__ == '__main__': | |
args = parser.parse_args() | |
print('just_string: {0}'.format(args.just_string)) | |
print('flag: {0}'.format(args.flag)) | |
print('value: {0}'.format(args.value)) | |
print('ids: {0}'.format(args.ids)) | |
print('csv_file: {0}'.format(args.csv_file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment