Home>
When multiple arguments are set with Python ArgumentParser, another argument type is received

I am creating a system that accepts command line arguments in Python and batches images.
I set multiple command line arguments with ArgumentParser, but I get the following error.

Error message
$python main.py mvfrom "./img/raw" input_dir = "./patients" output_dir = "./output" ext = ". tif" numfeature = 5000
usage: main.py [-h] [-wm] [-wc]
               mvfrom input_dir output_dir ext numfeature cropsize incsv
main.py: error: argument cropsize: invalid int value: 'output_dir'
Applicable source code
if __name__ == '__main__':
    #arg part
    parser = argparse.ArgumentParser ()
    parser.add_argument ("mvfrom", help = "mvfike input image directory specification. Example: ./img/raw", type = str)
    parser.add_argument ("input_dir", help = "Directory for writing the output image of mvfile and the directory that becomes the input of main", type = str, default = "./patients")
    parser.add_argument ("output_dir", help = "directory that is the main output", type = str, default = "./output")
    parser.add_argument ("ext", help = "input image extension", type = str, default = ".tif")
    parser.add_argument ("numfeature", help = "number of feature points used for orb", type = str, default = 5000)
    parser.add_argument ("-wm", "--wmove", help = "Whether to move the image", action = "store_true")
    parser.add_argument ("-wc", "--wcrop", help = "Would you like to crop the image", action = "store_true")
    args = parser.parse_args ()

No action has been taken since the verification method was No idea.

Supplemental information (FW/tool version etc.)

anaconda version 1.7.2

  • Answer # 1

    There is a problem with how to specify command line arguments.
    For positional arguments, pass only, not =.

    >python main.py "./img/raw" "./patients" "./output" ".tif" 5000