Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to correct "TypeError: 'int' object is not iterable"

having python code:
….

def DisplayTable(filename):
    #dir = os.path.dirname(__file__)
    fullFilename = dir+'/Data/'+str(filename)
    data = pd.read_csv(fullFilename, header=None)
    data=data.iloc[:: -1]
    print(data)
    stringList = [str(x) for x in data] 
    print(stringList)
    #data= tuple(data)
    headings=(" ", "Date", " ", "Temps")
    return render_template('fDetailTemps.html',  data=data, headings=headings)`

My HTML gives the error: TypeError: 'int' object is not iterable

I have tried several solutions found on this board, but none have helped (latest trial is in above code using str(x).)
the print(data) statement gives:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

4    Date:   2021-Dec-20, 04:00       Kombucha Temp:   77.56
3    Date:   2021-Dec-20, 03:00       Kombucha Temp:   77.79
2    Date:   2021-Dec-20, 02:00       Kombucha Temp:   77.79
1    Date:   2021-Dec-20, 01:00       Kombucha Temp:   77.90
0    Date:   2021-Dec-20, 00:00       Kombucha Temp:   77.79

and the print(string_list) gives:

['0', '1', '2', '3']

portion of the HTML code:

       <table>
        <tr>
           {% for header in headings %}
              <th>{{ header }} </th>
           {% endfor %}
        </tr>
        {% for row in data %}
           <tr>
               {% for cell in row %}
                  <td> {{ cell }} </td>
               {% endfor %}
           </tr>
        {% endfor %}
        </table>

>Solution :

Remove for cell in row inside of your HTML.

for row in data makes row the integer 0 or 1 or 2…etc and because of that for cell in row makes no sense as row is an integer not a list to iterate over.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading