title: How use input and output file in Python
body: <p>I have a Python script that inputs all words from a file and sorts them in order:</p>
  
  <pre><code>with open(raw_input("Enter a file name: ")) as f :
       for t in sorted(i for line in f for i in line.split()):
             print t
  </code></pre>
  
  <p>But instead of asking every time for the input file I would like to choose the input file with a "-i" and save the output file with a "-o", this way:</p>
  
  <pre><code>python myscript.py -i input_file.txt -o output_file.txt 
  </code></pre>
  
  <p>and BTW, how to save the output on a target file?</p>