Skip to content Skip to sidebar Skip to footer

Python Argparse Compare Input And Default File Names And Types Are Same?

def check_file(user_name,default_name): while True: try: #### check user name matches the default name if ('%s'%(user_name)) == '%s'%(default_na

Solution 1:

The add_argument method returns the Action that was just added. Which has details about the argument definition - including the default value.

import argparse

parser = argparse.ArgumentParser()

arg_action = parser.add_argument('-f', default='file')

print(arg_action.default)

Prints:

file

And you should be able to use that to compare the actual arguments with the default values.


Post a Comment for "Python Argparse Compare Input And Default File Names And Types Are Same?"