title: Parser in python3 does not take delimiter values from commandline via argparse
body: <p>I have written a simple script as an advanced tool for my <code>awk</code>/<code>sed</code> requirements. In the script I compare two files on basis of values from one column of the query file and then extract whole entries from the master file. The script allows you to enter the values for columns and delimiters for each file.</p>
  
  <p>The problem is that the 'delimiter' options are not recognized by script when given from command line.</p>
  
  <p>Here is my code (partial):</p>
  
  <pre><code>##- - - - - - - -- - - - - - Arguments - - - - - - - - - - - - - -##
  parser = argparse.ArgumentParser()
  
  ## Command line options
  parser.add_argument("-m",  "--master",     dest="master", help="master file")
  parser.add_argument("-q",  "--query",      dest="query",  help="queries to be extracted")
  parser.add_argument("-d",  "--delimiter",  dest="delimiter",  default='\t', help="delimiter in master")
  parser.add_argument("-p",  "--position",   dest="position",   default='1',  help="position/column of value in master")
  parser.add_argument("-d2", "--delimiter2", dest="delimiter2", default='\t', help="delimiter in query")
  parser.add_argument("-p2", "--position2",  dest="position2",  default='1',  help="position/column of value in query")
  
  args = parser.parse_args()
  
  def Extractor(master, query):
  
      out_file = ('%s_matched_%s' % (query,master))
      fh_out = open(out_file, 'w')
  
      query_set = () ## To unique query set
      for i in query:
          key = i.split('args.delimiter2')[int(args.position2)] ## Key is the value on which matching will be done
          query_set.add(key)
  </code></pre>
  
  <p>So as you see, I take options for the 'query file' delimiter from the command line and use them in the script via <code>argparse</code>, but that does not work. It only works if I explicitly mention the delimiter in the script like:</p>
  
  <pre><code>key = i.split('\t')[args.position2] ## Key is the value on which matching will be done
  </code></pre>
  
  <p>The command line option I give is:</p>
  
  <pre class="lang-none prettyprint-override"><code>$ py3 ExtractHeaders_v01.py -m ABC.csv -q XYZ.list -d2 \t -d , -p 1 -p2 0
  </code></pre>
  
  <p>where</p>
  
  <ul>
  <li><code>ABC.csv</code> is the master file from which to extract entries.
  
  <ul>
  <li>The second column will be used for matching (<code>-p 1</code>)</li>
  <li>Its delimiter is comma (<code>-d ,</code>)</li>
  </ul></li>
  <li><code>XYZ.list</code> is the query file.
  
  <ul>
  <li>The first column will be used for matching (<code>-p2 0</code>)</li>
  <li>Its delimiter is tab (<code>-d2 \t</code>)</li>
  </ul></li>
  </ul>
  
  <p>Please help me understand why the delimiters are not used by script when given from the command line.</p>