TypeError: argument of type 'method' is not iterable

17,148

Solution 1

You forgot to call the Entry.get() method:

q = variable1.get()
#                ^^ call the method

Because the method object itself doesn't support containment testing directly, Python is instead trying to iterate over the object to see if there are any elements contained in it that match your string.

If you call the method, you get a string value instead. Strings do support containment testing.

Solution 2

The reason you got that error was because you did not add "()" after.get query hence the error to fix this change q = variable1.get to q = variable.get()

Share:
17,148

Related videos on Youtube

Vipin Pritimani
Author by

Vipin Pritimani

Updated on June 04, 2022

Comments

  • Vipin Pritimani
    Vipin Pritimani almost 2 years

    Error

    Traceback (most recent call last):
      File "C:/Users/RCS/Desktop/Project/SHM.py", line 435, in <module>
        app = SHM()
      File "C:/Users/RCS/Desktop/Project/SHM.py", line 34, in __init__
        frame = F(container, self)
      File "C:/Users/RCS/Desktop/Project/SHM.py", line 384, in __init__
        if "3202" in q:
    TypeError: argument of type 'method' is not iterable
    

    code

    some part of code, initialisation and all

    while 1:
        q = variable1.get
        if "3202" in q:
            variable2.set("NI NODE3202")
            try:
                switch(labelframe2, labelframe1)
            except:
                switch(labelframe3, labelframe1)
        elif "3212" in q:
            variable2.set("NI NODE3212")
            try:
                switch(labelframe1, labelframe2)
            except:
                switch(labelframe3, labelframe2)
        elif "3214" in q:
            variable2.set("NI NODE3214")
            try:
                switch(labelframe1, labelframe3)
            except:
                switch(labelframe2, labelframe3)
        else:
            None
    

    some other part of code

    def switch(x, y):
    
        if x.isGridded:
            x.isGridded = False
            x.grid_forget()
            y.isGridded = True
            y.grid(row=0, column=0)
        else: 
            return False
    

    I am trying to create a switch between three labelframes which are inside another labelframe, and outside this labelframe are other labelframes that are not changing.

    I have read some similar answers but I don't want to use __iter__() in my code. Can anybody provide any other suggestions?

    • Anand S Kumar
      Anand S Kumar almost 9 years
      I am guessing you want to do - q = variable1.get() ?