How to read a file correctly in flask
<p>I would like to pass a list to Jinja that it can iterate over and populate the values of select field. I'm struggling to build the list correctly that be used to populate the select field correctly.</p>

<p>Data I have is list of strings that I read from a text file. Data in text file is in following format.</p>

<pre><code>['Afghanistan', 'Albania', 'Algeria']
</code></pre>

<p>I would like to iterate over these elements in jinja template and populate drop down list. My jinja template looks like this </p>

<pre><code>&lt;select name="country"&gt;
   {% for country in countryList %}    
      &lt;option value=""&gt;{{country}}&lt;/option&gt;
   {% endfor %}
&lt;/select&gt;
</code></pre>

<p>I have tried something like this to read from file</p>

<pre><code>with open(filename, 'r') as f:        
        data_list = f.read().replace('\n', ' ')
country_list = zip(data_list )

return render_template('signup.html', countryList= country_list)
</code></pre>

<p>but in jinja everything is read one character at a time.
I have tried this </p>

<pre><code>lines = tuple(open(filename, 'r'))
</code></pre>

<p>But that doesn't solve the issue either. In select field I only see '['</p>

<p>Other things I have tried</p>

<pre><code>with open(filename, 'r') as f:        
        array = []
        for line in f:
            array.append(line)


with open(filename, 'r') as f: 
     data_list = []       
     data_list = f.read().replace('\n', ' ')
</code></pre>

<p>I understand it is not Jinja or flask issue. But not sure how to read the data correctly from text file so that it is a list. Is there something I can try that could suggest problem with text file ? </p>