Filling command line arguments with a file

Category: Python - Miscellaneous

This is a recipe to populate command line args with the content of a file.

It is also an example of how to use the Action class from the argparse module.

I use this script in order to put frequently used options (such as for the scripts I write in config files.
I created an abstract class in order to inherit from it to implement several file formats.
Choice has been taken not to keep the file name in parsed args, but it can be done by adding:
setattr(namespace, self.dest, values)
at the end of the __call__ method.

Test functions at the end (even if the ugliest I've ever written and seen) explains the way it works. Date: 22 May, 2012


Argparse

Homepage: http://code.activestate.com/recipes/577918-filling-command-line-arguments-with-a-file/?in=lang-python

Developer: obernard78+activestate

License: Freeware

Operating System: Windows

Add a Comment

all are required fields

     
What do you think of this resource?

Select Your Rate:

Votes:0

 

Related Scripts Download

This little sample script looks up in locals() to determine all the callables in main.

developer Developer: Andrea Crotti
license License: Freeware
operating systems Operating System: Windows


Simple console tool that helps in maintenance your free days from work + basic tutorial how to use argparse in practice.

developer Developer: farciarz
license License: Freeware
operating systems Operating System: Windows


This is an implementation of the interface provided by the cmdln module but using argparse to provide the option/arg heavy parsing.

developer Developer: Shakeeb Alireza
license License: Freeware
operating systems Operating System: Windows


This is a simple example showing how to put a splash screen to work in a GTK app.

developer Developer: Nicolas Coelho
license License: Freeware
operating systems Operating System: Windows


The behaviour of applications sometimes depends on various parameters that can be chosen by the user through some GUI.

developer Developer: s_h_a_i_o
license License: Freeware
operating systems Operating System: Windows