0

正规365体育投注I'm trying to set an argument in a "fromfile" text file, but it's not recognised, however if I copy/paste the SAME arguments into the command line, it works! What's going on?

Here's a minimal example:

A main.py正规365体育投注 like this:

def main(args):
    pass

if __name__ == '__main__':
    parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
    parser.add_argument("--load-model", default=None, help="model to load")
    main(parser.parse_args())

And text file args.txt:

--load-model foo

Called like this:

> python main.py @args.txt
usage: main.py [--load-model LOAD_MODEL]
main.py: error: unrecognized arguments: --load-model foo

But the "unrecognised argument" is identical to the argument listed above ??

0

It turns out that the "fromfile" text file needs to be delimited by newlines.

If my argument file is like this:

--load-model
foo

it works!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy正规365体育投注

Not the answer you're looking for? Browse other questions tagged or ask your own question.