My function doesn't return a value, can't figure out why
<p>The function is supposed to open a csv file that has data in this format</p>

<p>"polling company,date range,how many polled,margin of error,cruz,kasich,rubio,trump"</p>

<p>When I run this function, read_data_file, there is no output, which I don't understand since I am returning the poll_data. I don't believe there is an issue with the rest of the code as if I replaced 'return poll data' with 'print(poll_data)' there is the desired output. </p>

<p>I am a noob at this and don't have a full grasp of return. </p>

<pre><code>def read_data_file(filename):
    file = open(filename, 'r')
    poll_data = []
    for data in file:
        data = data.strip('\n')
        data = data.split(',')
        poll_data.append(data)
    return poll_data


read_data_file('florida-gop.csv')
</code></pre>

<p>You have two options here:</p>

<ol>
<li>Replacing <code>return poll_data</code> with <code>print poll_data</code>.</li>
<li>Instead of <code>read_data_file('florida-gop.csv')</code>, you can do <code>print read_data_file('florida-gop.csv')</code>.</li>
</ol>

<p>Why do you need to do this? </p>

<p><strong><code>Print</code> vs <code>Return</code></strong></p>

<p><code>print</code> actually shows you the result, while <code>return</code> only gives the result to the computer, if that makes sense. The computer knows it, but it doesn't print it, which is why the second solution works - the computer has the data you want, and it is able to print it if you command it too. However, in your case, the first solution is probably easier. </p>

<p>Hope this helps!</p>

python function return