Popular recipes tagged "argparse"http://code.activestate.com/recipes/tags/argparse/2014-10-25T22:29:10-07:00ActiveState Code Recipesbeep based alarm - command line utility (Python) 2014-10-25T22:29:10-07:00Tomas Nordinhttp://code.activestate.com/recipes/users/4189558/http://code.activestate.com/recipes/578953-beep-based-alarm-command-line-utility/ <p style="color: grey"> Python recipe 578953 by <a href="/recipes/users/4189558/">Tomas Nordin</a> (<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/beep/">beep</a>, <a href="/recipes/tags/commandline/">commandline</a>). Revision 2. </p> <p>An alarm beeping on you when the eggs are boiled.</p> Generate automatically list of actions with argparse (Python) 2011-12-02T10:25:13-08:00Andrea Crottihttp://code.activestate.com/recipes/users/4179946/http://code.activestate.com/recipes/577947-generate-automatically-list-of-actions-with-argpar/ <p style="color: grey"> Python recipe 577947 by <a href="/recipes/users/4179946/">Andrea Crotti</a> (<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cli/">cli</a>). Revision 2. </p> <p>This little sample script looks up in locals() to determine all the callables in <em>main</em>.</p> <p>Then it passes them to parse_arguments, which show an help message as following usage:</p> <pre class="prettyprint"><code>prova.py [-h] {func2,func1} positional arguments: {func2,func1} optional arguments: -h, --help show this help message and exit </code></pre> <p>Useful to avoid duplication and make it easy to extend script functions.</p> Filling 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> Holiday Leave (Python) 2010-07-01T13:21:09-07:00farciarzhttp://code.activestate.com/recipes/users/4172795/http://code.activestate.com/recipes/577280-holiday-leave/ <p style="color: grey"> Python recipe 577280 by <a href="/recipes/users/4172795/">farciarz</a> (<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/console/">console</a>, <a href="/recipes/tags/holiday/">holiday</a>, <a href="/recipes/tags/leave/">leave</a>). </p> <p>Simple console tool that helps in maintenance your free days from work + basic tutorial how to use argparse in practice. It's clear and few lines of code. Enjoy! :-)</p> argdeclare: declarative interface to argparse (Python) 2010-03-02T00:05:40-08:00Shakeeb Alirezahttp://code.activestate.com/recipes/users/4172101/http://code.activestate.com/recipes/576935-argdeclare-declarative-interface-to-argparse/ <p style="color: grey"> Python recipe 576935 by <a href="/recipes/users/4172101/">Shakeeb Alireza</a> (<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cmdln/">cmdln</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/getopt/">getopt</a>, <a href="/recipes/tags/metaclass/">metaclass</a>, <a href="/recipes/tags/option/">option</a>). Revision 5. </p> <p>This is an implementation of the interface provided by the <a href="http://code.google.com/p/cmdln/">cmdln</a> module but using <a href="http://code.google.com/p/argparse/">argparse</a> to provide the option/arg heavy parsing.</p> <p>An example of usage is provided in the <code>test</code> function, which should produce the following from the command line:</p> <p>$ python argdeclare.py --help</p> <pre class="prettyprint"><code>usage: argdeclare.py [-h] [-v] {uninstall,install,delete} ... a description of the test app optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit subcommands: valid subcommands {uninstall,install,delete} additional help delete help text for delete subcmd install help text for install subcmd uninstall help text for uninstall subcmd </code></pre> <p>$ python argdeclare.py install --help</p> <pre class="prettyprint"><code>usage: argdeclare.py install [-h] [-t TYPE] [--log] [-f] package positional arguments: package package to be (un)installed optional arguments: -h, --help show this help message and exit -t TYPE, --type TYPE specify type of package --log, -l log is on -f, --force force through installation </code></pre> <p>enjoy!</p> <p>SA</p> Send Email (Python) 2012-08-26T11:23:54-07:00sfwgeekhttp://code.activestate.com/recipes/users/4170734/http://code.activestate.com/recipes/576807-send-email/ <p style="color: grey"> Python recipe 576807 by <a href="/recipes/users/4170734/">sfwgeek</a> (<a href="/recipes/tags/argparse/">argparse</a>, <a href="/recipes/tags/cli/">cli</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/interface/">interface</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/send/">send</a>, <a href="/recipes/tags/smtplib/">smtplib</a>). Revision 5. </p> <p>A Command Line Interface (CLI) program to send email.</p>