[issue35005] argparse should accept json and yaml argument types

paul j3 report at bugs.python.org
Wed Oct 17 02:47:21 EDT 2018


paul j3 <ajipanca at gmail.com> added the comment:

The results of reading one of these @-prefix files are just spliced into the `argv` list before it is parsed.  This is done early in the parsing method, in the 

_read_args_from_files

method.  The documentation illustrates how this file reading can be modified to take several strings from each line:

https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.convert_arg_line_to_args

That shouldn't be taken as the only possible modification.

That said, I don't see how reading from a JSON or YAML file fits with this mechanism.  Presumably those would define some dictionary like key:value pairs.  I assume you'd want to enter those directly into the Namespace, not the argv list that will be parsed.  Or otherwise merged with a dictionary produced by parsing the other commandline strings.

So what you want to do with a JSON file, and how that relates to argparse is not clear.  You need to elaborate before we can discuss this issue further.

You might want to search on Stackoverflow with the tags '[argparse] [json]' to see how others have tried to use the two together.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35005>
_______________________________________


More information about the Python-bugs-list mailing list