Python Forum
how to solve `'TypeError: 'int' object is not iterable`?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to solve `'TypeError: 'int' object is not iterable`?
#1
Question 
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
Reply
#2
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.
Reply
#3
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Did you know that map() accepts more than one iterable? DeaD_EyE 2 513 Apr-13-2025, 10:16 AM
Last Post: noisefloor
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 7 3,415 Mar-09-2025, 04:25 PM
Last Post: Pedroski55
Question TypeError: argument of type 'NoneType' is not iterable Tajaldeen 7 2,436 Nov-29-2024, 09:45 AM
Last Post: Tajaldeen
  I am getting this TypeError: 'TreasureMap' object is not subscriptable. makilakos 2 1,248 May-25-2024, 07:58 PM
Last Post: deanhystad
  TypeError: cannot pickle ‘_asyncio.Future’ object Abdul_Rafey 1 2,734 Mar-07-2024, 03:40 PM
Last Post: deanhystad
  error in class: TypeError: 'str' object is not callable akbarza 2 1,752 Dec-30-2023, 04:35 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 3,630 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  TypeError: 'NoneType' object is not callable akbarza 4 14,074 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 5,635 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable #1 isdito2001 1 1,904 Jan-21-2023, 12:43 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020