Positional arguments

We define positional arguments using a name with no "-" decoration. In a case where we have a fixed number of positional arguments, we'll add them appropriately to the parser, as shown in the following code:

parser.add_argument("input_filename", action="store") 
parser.add_argument("output_filename", action="store") 

When parsing argument values, the two positional argument strings will be stored in the final namespace object. We can use config.input_filename and config.output_filename to work with these argument values.

As noted previously, using simple positional parameters to identify output files can cause problems for users. The GNU/Linux cp, mv, and ln programs should be considered exceptional cases where a file can get overwritten. The preferred approach is to use an option with a value to specify the files that can be destroyed. It's almost always safer to force users to use an option like -o name.csv to make it perfectly clear what the output filename will be.

Avoid defining commands where the exact order of arguments is significant.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset