title: Python [float(n) for n in line.split()] over a file that contains only one column
body: <p>I have created a python script where I write in a file an array of <code>V</code> (volumes) in a column:</p>
  
  <pre><code> import numpy as np
  
   volume_pressure_energy = open('datafile.dat', 'w') # Open the file, 'w' for writing
   V = np.linspace(62, 72, 5)
   with open('datafile.dat') as volume_pressure_energy:
      np.savetxt('datafile.dat', V, '%10.9f', delimiter='\t', header=" volume\tpressure\tenergy")
  
   volume_pressure_energy.close()
  </code></pre>
  
  <p>This generates this file <code>datafile.dat</code> : </p>
  
  <pre><code> #  volume       pressure        energy
   62.000000000
   64.500000000
   67.000000000
   69.500000000
   72.000000000
  </code></pre>
  
  <p>The next lines of the script try to calculate the <code>pressure</code> and the <code>energy</code> using functions and parameters:</p>
  
  <pre><code># Parameters
   E0 = -9
   B0 = 7
   V0 = 6
   B0_prime = 4
  
  # Function P(V):
   def P(V): # To use a P(V) is inevitable as the function depends on V
     f0=(3.0/2.0)*B0
     f1=((V0/V)**(7.0/3.0))-((V0/V)**(5.0/3.0))
     f2=((V0/V)**(2.0/3.0))-1
     pressure= f0*f1*(1+(3.0/4.0)*(B0_prime-4)*f2)
     return pressure
  
  # Function E(V):
   def E(V):
     E = E0+ (2.293710449E+17)*(1E-21)*( (9.0/16.0)*(V0*B0) * (  (((V0/V)**   (2.0/3.0)-1)**3)*B0_prime  + ((V0/V)**(2.0/3.0)-1)**2  *  (6.0-4.0*(V0/V)**(2.0/3.0))  ))
     return E
  </code></pre>
  
  <p>Now, I would like to read <code>datafile.dat</code> and treat the first column as <code>volume</code> data. This <code>volume</code> data will enter the function <code>P(V)</code>,  and will give me <code>pressure</code>. Similarly, this <code>volume</code> data will enter the function <code>E(V)</code> and will give me <code>energy</code>:</p>
  
  <pre><code> with open('datafile.dat') as   volume_pressure_energy: # open the file
     volume_pressure_energy.next() # skip the first line
     for line in volume_pressure_energy:
     volume = [float(n) for n in line.split()] # split the lines 
     # (removes linebreaks, tabs and spaces)
     # convert all items to floats.
     pressure = P(volume) # call my function
     energy = E(volume)   # call my function
     volume_pressure_energy.write('{}\t{}\t{}\n'.format(volume, pressure, energy))
   volume_pressure_energy.close()
  </code></pre>
  
  <p>When running all this script (below I have posted the <strong>complete script</strong>), it says that   </p>
  
  <pre><code> Traceback (most recent call last):
   File "BM-model-Enth-obtention_data_E_vs_P.py", line 76, in &lt;module&gt;
   pressure = P(volume) # call your function
   File "BM-model-Enth-obtention_data_E_vs_P.py", line 50, in P
   f1=((V0/V)**(7.0/3.0))-((V0/V)**(5.0/3.0))
   TypeError: unsupported operand type(s) for /: 'float' and 'list'
  </code></pre>
  
  <p>Apparently, there is a problem with the functions. I have runned them separately and work fine, so the problem is that python is not assuming that each line of the first column of <code>datafile.dat</code>, contains the <code>V</code>, the volumes that are inserted in the functions.</p>
  
  <p>Why happens this?  <code>volume = [float(n) for n in line.split()]</code> is splitting  the lines and converts all items to floats, so why this should be the problem?</p>
  
  <p><strong>Complete script:</strong></p>
  
  <pre><code>import numpy as np
  
  volume_pressure_energy = open('datafile.dat', 'w') # Open the file, 'w' for writing
  V = np.linspace(62, 72, 5)
  with open('datafile.dat') as volume_pressure_energy:
     np.savetxt('datafile.dat', V, '%10.9f', delimiter='\t', header=" volume\tpressure\tenergy")
  
  volume_pressure_energy.close()
  
  # Parameters
  E0 = -9
  B0 = 7
  V0 = 6
  B0_prime = 4
  
  # Function P(V):
    def P(V): # To use a P(V) is inevitable as the function depends on V
     f0=(3.0/2.0)*B0
     f1=((V0/V)**(7.0/3.0))-((V0/V)**(5.0/3.0))
     f2=((V0/V)**(2.0/3.0))-1
     pressure= f0*f1*(1+(3.0/4.0)*(B0_prime-4)*f2)
     return pressure
  
  # Function E(V):
    def E(V):
     E = E0+ (2.293710449E+17)*(1E-21)*( (9.0/16.0)*(V0*B0) * (  (((V0/V)**   (2.0/3.0)-1)**3)*B0_prime  + ((V0/V)**(2.0/3.0)-1)**2  *  (6.0-4.0*(V0/V)**(2.0/3.0))  ))
     return E
  
  with open('datafile.dat') as   volume_pressure_energy: # open the file
  volume_pressure_energy.next() # skip the first line
  for line in volume_pressure_energy:
     volume = [float(n) for n in line.split()] # split the lines 
     # (removes linebreaks, tabs and spaces)
     # convert all items to floats.
     pressure = P(volume) # call my function
     energy = E(volume)   # call my function
     volume_pressure_energy.write('{}\t{}\t{}\n'.format(volume, pressure, energy))
  volume_pressure_energy.close()
  </code></pre>