Search code examples
pythonmaya

# Error: TypeError: argument of type 'bool' is not iterable #


first post! I am fairly new to python and trying to improve, any help would be greatly appreciated! I've looked through other posts with similar questions still cant seem to get around this issue.

This is the error I receive, which happens on line 5:

    # Error: TypeError: argument of type 'bool' is not iterable # 

This is my code:

userInput = cmds.textFieldGrp(searchText, query = True, text=True)
path = "D:\somefolder"
for root, dirs, files in os.walk(path):
    for file in files:
        if (userInput in file.endswith('.ma')):
            print file
        else:
            break
            print "No files containing %s" (userInput)

Basically, I am trying to search for files in a directory based off keywords a user types in.

Looking forward to hearing from anyone, thank you!


Solution

  • assuming that you are trying to get only the files that ends with .ma and filename containing the queryterm try example below and see if this helps

    userInput = cmds.textFieldGrp(searchText, query = True, text=True)
    path = "D:\somefolder"
    for root, dirs, files in os.walk(path):
        for file in files:
            if ((userInput in file) and file.endswith('.ma')):
                print file
            else:
                break
                print "No files containing %s" (userInput)