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>

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

<p>For more complex command line interfaces there is the <a href="https://docs.python.org/3/library/argparse.html" rel="nofollow"><code>argparse</code></a> module
in Python's standard library - but for simple projects taking just a couple parameters directly checking <code>sys.argv</code> is alright. </p>

python linux