title: How to open a file using argparse.FileType only if a condition is satisfied?
body: <p>I am using python 3 argparse. I have multiple files passed as <code>argparse.FileType</code> which I use to write some data. I want to check some conditions and open those files only if they are met. However argparse opens them immediately, and they are created even if I exit with error code.</p>
  
  <pre><code>import argparse
  from sys import exit
  
  def main():
      parser = argparse.ArgumentParser()
      parser.add_argument('--condition', action='store_true')
      parser.add_argument('out1', type=argparse.FileType('w'))
      parser.add_argument('out2', type=argparse.FileType('w'))
  
      args = parser.parse_args()
  
      if not args.condition:
          print('ERROR: please use --condition')
          exit(2)
  
      args.out1.write('hello\n')
      args.out2.write('world\n')
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>If I run this example without passing the <code>--condition</code> argument, it will still create 2 new files. I don't want to create them in that case. Can I do that without passing filename and opening the files manually?</p>