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>I tried running your script at the command line and it works perfectly:</p>

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

<p>In the above, the <code>$</code> is the shell's prompt.  What I entered is <code>python arg.py 1 2 3 4 --sum</code>.  It works.</p>

<p>Now, let's do what I suspect that you are doing: let's start an interactive python shell and enter the above:</p>

<pre><code>$ python
Python 2.7.12+ (default, Aug  4 2016, 20:04:34) 
[GCC 6.1.1 20160724] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; python test.py 1 2 3 4 --sum 
  File "&lt;stdin&gt;", line 1
    python test.py 1 2 3 4 --sum 
              ^
SyntaxError: invalid syntax
</code></pre>

<p>This generates the <code>SyntaxError: invalid syntax</code> error that you see.  (There is one minor difference: I am on Linux and you are on Windows.)</p>

<p>The solution is to exit the python interactive shell and enter the command at the command prompt.</p>

python argparse