title: Remove whitespaces from beginning and end of each line in a file in python
body: <p>I am trying to read some numbers from a file and store them into an array called <code>numbers</code>.
  I use <code>strip()</code> for each line to remove the <code>\n</code> at the end of each line. I also use <code>split(' ')</code> for each line to remove the spaces between the numbers. </p>
  
  <p>The problem is that in the input file the first character on the line and the last character on the line are spaces. How can I erase them?</p>
  
  <p>This is my code:</p>
  
  <pre><code>def read_from_file():
      f = open('input_file.txt')
      numbers = []
      for eachLine in f:
          line = eachLine.strip()
          for x in eachLine.split(' '):
              line2 = int(x)
              numbers.append(line2)
      f.close()
      print numbers
  </code></pre>
  
  <p>This is the text file, where the underscores are spaces:</p>
  
  <pre><code>_9 5_
  _2 3 1 5 4_
  _2 1 5_
  _1 1_
  _2 1 2_
  _2 2 3_
  _2 3 4_
  _3 3 4 5_
  _2 4 5_
  _2 1 5_
  _3 1 2 5_
  </code></pre>