title: python 2.7 check if argument has been passed from command prompt
body: <p>kind of stuck in a problem. I need to check if a certain parameter has been passed via command prompt while executing a python script. </p>
  
  <p>I execute the python file as <code>python run.py -ip 127.0.0.1 -trigger 1</code></p>
  
  <p>While on my python script I used <code>argparse</code> as</p>
  
  <pre><code>parser = argparse.ArgumentParser()
  parser.add_argument('-ip', '--ip')
  args = parser.parse_args()
  </code></pre>
  
  <p>How can i check if the argument <code>trigger</code> has been passed or not. If there is trigger in the parameter then grab the value of trigger and print it. </p>
  
  <p>And the script should be able to run with all of following commands</p>
  
  <p><code>python run.py -ip 127.0.0.1</code> without the trigger parameter. </p>
  
  <p><code>python run.py -ip 127.0.0.1 -trigger</code> without the value of the trigger parameter.</p>
  
  <p><code>python run.py -ip 127.0.0.1 -trigger 1</code> with all the parameters and its value.</p>
  
  <p>Further more the execution command is auto generated from an automated system, and hence the parameters can be more, For example, The command can be  <code>python run.py -ip 127.0.0.1 -trigger 1 prompt 0 base 5 .....</code> , and the <code>-trigger 1 prompt 0 base 5</code> etc are auto generated, therefore I want to implement the <code>parameter check</code> in my python script so that it can handle any number of the passed parameters.</p>