Python default parameter if no command line arguments are passed
<p>I'l like to build a program with this behaviour:</p>

<p>usage: sage 4ct.py [-h] (-r R | -i I | -p P) [-o O]</p>

<p>But if you don't give any parameter, I'd like to have "-r 100" as the default.</p>

<p>Is it possible?</p>

<pre><code>parser = argparse.ArgumentParser(description = '4ct args')

group_input = parser.add_mutually_exclusive_group(required = True)
group_input.add_argument("-r", "-random", help = "Random graph: dual of a triangulation of N vertices", nargs = 1, type = int, default = 100)
group_input.add_argument("-i", "-input", help = "Input edgelist filename (networkx)", nargs = 1)
group_input.add_argument("-p", "-planar", help = "Load a planar embedding of the graph G.faces() - Automatically saved at each run: input_planar_file.serialized", nargs = 1)
parser.add_argument("-o", "-output", help="Output edgelist filename (networkx)", nargs = 1, required = False)

args = parser.parse_args()
</code></pre>

<p>Give the following a try:</p>

<pre><code>import argparse
import sys

parser = argparse.ArgumentParser(description='4ct args')

group_input = parser.add_mutually_exclusive_group(required=True)
group_input.add_argument("-r", "-random", help="Random graph: dual of a triangulation of N vertices", nargs=1, type=int,             default=100)
group_input.add_argument("-i", "-input", help="Input edgelist filename (networkx)", nargs=1)
group_input.add_argument("-p", "-planar", help="Load a planar embedding of the graph G.faces() - Automatically saved at each run: input_planar_file.serialized",nargs=1)
parser.add_argument("-o", "-output", help="Output edgelist filename (networkx)", nargs=1, required=False)

if not sys.argv[1:]:
    sys.argv.extend(['-r', '100'])

args = parser.parse_args(sys.argv[1:])
</code></pre>

<p>Essentially you are checking  if any commandline parameters are given at all, and if not, you append the desired <code>-r 100</code></p>

python argparse