Table of contents
vars()
-
Create a class
ParamGroupto store args into instance variables, then usevars(self)to read memebers fromself.__dict__. -
Add each argument into parser through
parser.add_argument(). -
Set shorthand to the initial character, e.g.,
--source_pathuse-s
Example from gaussian-splatting:
|
|
(2024-04-03)
-
In this way, there won’t be a long list of
parser.add_argument()declaiming all arguments.Instead, related arguments are arranged into a group.
Customize Parsing
(2023-09-27)
-
Analyse string manually
Refer to Match-NeRF for an example.
Specify Args in Scripts
(2024-07-19)
-
Specifying default values for arguments for debugging.
Initialize a parser and then change it:
1 2 3 4 5 6 7 8 9 10 11parser = argparse.ArgumentParser(description="A Func") parser.add_argument("-f", "--filename", default="f.txt", type=str, help="File name.") def main(): # . . . return if __name__ == "__main__": # args = parser.parse_args() args, unknown = parser.parse_known_args() args.filename = 'b.txt'The following examples all pass the
argsinto the main function, like:eval(args)