How do I open a text file in Python?
<p>Currently I am trying to open a text file called "temperature.txt" i have saved on my desktop using file handler, however for some reason i cannot get it to work. Could anyone tell me what im doing wrong.</p>

<pre><code>#!/Python34/python
from math import *

fh = open('temperature.txt')

num_list = []

for num in  fh:
    num_list.append(int(num))

fh.close()
</code></pre>

<p>You simply need to use .readlines() on fh</p>

<p>like this:</p>

<pre><code>#!/Python34/python
from math import *

fh = open('temperature.txt')

num_list = []

read_lines = fh.readlines()
for line in read_lines:
    num_list.append(int(line))

fh.close()
</code></pre>

python python-3.x filehandler