How to check if the parameter exist in python
<p>I would like to create a simple python script that will take a parameter from the console, and it will display this parameter. If there will be no parameter then I would like to display error message, but custom message not something like IndexError: list index out of range</p>

<p>Something like this:</p>

<pre><code>if isset(sys.argv[1]):
    print sys.argv[1];
else:
    print "No parameter has been included"
</code></pre>

<p>You can check the lenght </p>

<pre><code>if len(sys.argv) &gt; 1:
    ...
</code></pre>

<p>Or the try/except</p>

<pre><code>try:
    sys.argv[1]
except IndexError as ie:
    print("Exception : {0}".format(ie))
</code></pre>

python linux