args python parser, a whitespace and Spark
<p>I have this code in <code>foo.py</code>:</p>

<pre><code>from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('--label', dest='label', type=str, default=None, required=True, help='label')
args = parser.parse_args()
</code></pre>

<p>and when I execute:</p>

<blockquote>
  <p>spark-submit --master yarn --deploy-mode cluster foo.py --label 106466153-Gateway Arch</p>
</blockquote>

<p>I get this error at Stdout:</p>

<pre><code>usage: foo.py [-h] --label LABEL
foo.py: error: unrecognized arguments: Arch
</code></pre>

<p>Any idea(s) please?</p>

<hr>

<p>Attempts:</p>

<ol>
<li><code>--label "106466153-Gateway Arch"</code></li>
<li><code>--label 106466153-Gateway\ Arch</code></li>
<li><code>--label "106466153-Gateway\ Arch"</code></li>
<li><code>--label="106466153-Gateway Arch"</code></li>
<li><code>--label 106466153-Gateway\\\ Arch</code></li>
<li><code>--label 106466153-Gateway\\\\\\\ Arch</code></li>
</ol>

<p>All attempts produce the same error.</p>

<hr>

<p>I am using Red Hat Enterprise Linux Server release 6.4 (Santiago).</p>

<p>Here is a nasty workaround:</p>

<pre><code>from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('--label', dest='label', type=str, default=None, required=True, help='label', nargs="+")
args = parser.parse_args()
args = ' '.join(args.label)
print args
</code></pre>

<p>where I am using <code>nargs="+"</code> and then <code>join</code> the arguments. </p>

<p>I execute like this:</p>

<blockquote>
  <p>spark-submit --master yarn --deploy-mode cluster foo.py --label "106466153-Gateway Arch"</p>
</blockquote>

<p>Also notice that this approach can work when no space exists, like this:</p>

<blockquote>
  <p>spark-submit --master yarn --deploy-mode cluster foo.py --label "106466153-GatewayNoSpaceArch"</p>
</blockquote>

python linux apache-spark io redhat