Код: Выделить всё
import argparse, sys
def get_image_argument():
parser = argparse.ArgumentParser(
description="Please specify a image file'."
)
parser.add_argument(
"-i", "--file", help="Please use -h or --help to see usage.", dest="image"
)
argument = parser.parse_args()
if not argument.image:
print("[-] Please specify an image file. Use --help to see usage.")
sys.exit() # Exit the program
return argument
image_args = get_image_argument()
print(image_args)
my_image = f"my_{image_args}"
print(my_image)
Я получаю:
Код: Выделить всё
Namespace(image='test.jpg')
my_Namespace(image='test.jpg')
Подробнее здесь: https://stackoverflow.com/questions/798 ... -file-name
Мобильная версия