Python Forum

Full Version: how to solve `'TypeError: 'int' object is not iterable`?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def CSVR():

    
   x52=[""]
   x166=[""]
   if request.method == 'POST':
       f = request.files['file']
       l8=range(48,58)
       l81=[]
       l82=[]
       l9=range(97,103)
       for x1 in l8:
           l81.append(x1)
       for y1 in l9:
           l82.append(y1)
        

       f.save(utils.secure_filename(f.filename))
       csr=pd.read_csv(utils.secure_filename(f.filename))
       J4=csr.to_numpy()
       for i in J4:
           for j in i:
               x=ord(j[0])
               if(x in list(x1)) or (x in list(y1)):
                  print(J4[0][j])


       j=csr.to_dict()[request.form.get("col-name")]
       j=dict(j)
       x222=dict2SemiColonSV(j)

       t=f"/indicators/{x222}/{x222}/{x222}"
       return flask.redirect(t)
tnx
nate
Is this code a part of the obfuscated Python code contest? As we don't know where the error occurs because you did not post the exception traceback, let us suppose that after J4 = csr.to_numpy(), J4 is an numpy array of integers, then after for i in J4, i is an integer. An integer is not iterable, so you can't write for j in i.

The solution is to not iterate on an integer. Do not write for j in i if i is an integer.
for j in range(i): should get you past your dilemma, but you are sure to be back with more problems if you don't change your variable naming conventions. Unreadable!