Popular recipes by obernard78+activestate http://code.activestate.com/recipes/users/4179024/2011-10-24T13:13:04-07:00ActiveState Code RecipesFilling command line arguments with a file (Python) 2011-10-24T13:13:04-07:00obernard78+activestatehttp://code.activestate.com/recipes/users/4179024/http://code.activestate.com/recipes/577918-filling-command-line-arguments-with-a-file/ <p style="color: grey"> Python recipe 577918 by <a href="/recipes/users/4179024/">obernard78+activestate</a> (<a href="/recipes/tags/argparse/">argparse</a>). </p> <p>This is a recipe to populate command line args with the content of a file.</p> <p>It is also an example of how to use the Action class from the argparse module.</p> <p>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 <code>__call__</code> method.</p> <p>Test functions at the end (even if the ugliest I've ever written and seen) explains the way it works.</p>