How to read values from from a text file with columns?
<p>I'm trying to read data from a file that is separated in columns with data from each year and lines with the name of the values (eg:number of times I opened Firefox on the year 2015). Now, I know how to read a specific line but I'm having trouble reading from the different columns. They are 10 spaces wide but only have values like -0.5 and 1.2, so it doesn't get to the tenths and only 1 decimal. Like this:</p>

<pre><code>-3.5         1.0        -2.9         6.8
</code></pre>

<p>How would I do it to read these values since I have to compare them as floats to other data? Would I slice it? If so I haven't found a way to do so.</p>

<p>If you know how many columns you are going to have you can split the whitespace and coerce to a float:</p>

<pre><code>[float(i) for i in "-3.5         1.0        -2.9         6.8".split()]
</code></pre>

<p>Yields:</p>

<pre><code>[-3.5, 1.0, -2.9, 6.8]
</code></pre>

python slice