I am parsing some command-line arguments, and most of them need to be passed to a method, but not all.
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--dir", help = "Directory name", type = str, default = "backups")
parser.add_argument("-n", "--dbname", help = "Name of the database", type = str, default = "dmitrii")
parser.add_argument("-p", "--password", help = "Database password", type = str, default = "1123581321")
parser.add_argument("-u", "--user", help = "Database username", type = str, default = "Dmitriy")
parser.add_argument("-a", "--archive", help = "Archive backup", action="store_true")
args = parser.parse_args()
backup(**vars(args)) # the method where i need to pass most of the arguments, except archive. Now it passes all.
Either create a new dictionary that does not have that key:
new_args = dict(k, v for k, v in args.items() if k != 'archive')
Or remove the key from your original dictionary:
archive_arg = args['archive'] # save for later
del args['archive'] #remove it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With