title: How to give an input-file as argument an read it in Python?
body: <p>I am trying to give an input file as an argument in Python using argparse, but somehow, Im getting an error.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>from argparse import ArgumentParser
  
  def main():
      args = arg_parser.parse_args()
      print('in main, args = ',args)
      input_file = args.input_file
      update_file_input(input_file)
  
  if __name__ == '__main__':
      import argparse
  
      parser = argparse.ArgumentParser(description="less script")
      parser.add_argument('--input_file', required=True, help="input file containing IDs and attributes to change (csv)")
      args = parser.parse_args()
      print('args is: ',args)
      main()
  </code></pre>
  
  <p>I am calling the script with the following command from command line:</p>
  
  <pre><code>python updaterScript.py --input_file myCSVFile.csv
  </code></pre>
  
  <p>What am I doing wrong here? Why am I getting an error? </p>
  
  <p>Here is the error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/ProjectP/runtime/bin/updaterScript.py", line 11, in &lt;module&gt;
      load_entry_point('ProjectP==1.0', 'console_scripts', 'updaterScript.py')()
    File "/home/ProjectP/runtime/lib/python3.6/site-packages/ProjectP/updaterScript.py", line 10
  0, in main
      args = arg_parser.parse_args()
  </code></pre>
  
  <p>NameError: name 'arg_parser' is not defined</p>