Python program with arguments on Windows
<p>How to run this program saved in the file test.py on Windows XP with python 2.7 installed.</p>

<pre><code>import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('integers', metavar='N', type=int, nargs='+',help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',const=sum, default=max,help='sum the integers (default: find the max)')
args = parser.parse_args()
print args.accumulate(args.integers)
</code></pre>

<p>I tried to run it with command line. For example</p>

<pre><code>$ python test.py 1 2 3 4
</code></pre>

<p>or</p>

<pre><code>$ python test.py 1 2 3 4 --sum
</code></pre>

<p>gives error "invalid syntax".</p>

<p>This is just me being naive, but considering the short error message you posted...</p>

<p>Any chance you're getting this code off some book and try to run this on a command line?</p>

<p>The book uses <code>$</code> to mark command line/terminal commands, but the character is actually not part of the syntax or command you're supposed to use.</p>

<p>So instead of running this:</p>

<pre><code>$ python 1 2 3
</code></pre>

<p>Run this:</p>

<pre><code>python 1 2 3
</code></pre>

python argparse