Python #错误:TypeError:类型为';布尔';这是不可容忍的#
第一个帖子!我是python新手,正在努力改进,如果有任何帮助,我将不胜感激!我浏览了其他类似问题的帖子,但似乎仍然无法回避这个问题 这是我收到的错误,发生在第5行:Python #错误:TypeError:类型为';布尔';这是不可容忍的#,python,maya,Python,Maya,第一个帖子!我是python新手,正在努力改进,如果有任何帮助,我将不胜感激!我浏览了其他类似问题的帖子,但似乎仍然无法回避这个问题 这是我收到的错误,发生在第5行: # Error: TypeError: argument of type 'bool' is not iterable # 这是我的代码: userInput = cmds.textFieldGrp(searchText, query = True, text=True) path = "D:\somefolder"
# Error: TypeError: argument of type 'bool' is not iterable #
这是我的代码:
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)
基本上,我试图根据用户键入的关键字在目录中搜索文件
期待收到任何人的来信,谢谢 您当前收到的错误是由于
userInput in file.endswith('.ma')
那条线没有做你认为它在做的事
file.endswith('.ma')
返回一个bool
。错误是告诉您正在尝试迭代bool。语句中的检查iterable中的成员身份。有关
中的如何工作的更多信息,请查看答案
下面是一个单独的演示,向您展示如何再现错误:
>>> 's' in False:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument of type 'bool' is not iterable
假设您试图仅获取以.ma
结尾的文件以及包含queryterm的文件名,请尝试下面的示例,看看这是否有帮助
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)
尝试使用print yourself调试。当前出现的错误是由于.endswith('.ma')文件中的用户输入造成的。
。该行没有执行您认为它正在执行的操作。您所说的file.endswith('.ma')
是什么意思?您是否试图检查文件的扩展名是.ma
,还是以文本file.endswith('.ma')
结尾。如果稍后打开,则必须打开并读取文件文件.endswith('.ma')
如果文件以'.ma'结尾,则返回True
。您所做的是:如果'hello'为True:
。谢谢!用“in”和“out”进行检查。非常感谢!!这些信息对理解发生了什么也很有帮助,谢谢!
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)