Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python如何克服类型错误:';布尔';对象是不可编辑的_Python_Python 3.x_If Statement - Fatal编程技术网

Python如何克服类型错误:';布尔';对象是不可编辑的

Python如何克服类型错误:';布尔';对象是不可编辑的,python,python-3.x,if-statement,Python,Python 3.x,If Statement,我的问题是在ifany()语句中需要有两个条件,这两个条件检查列表中的一个单词是否出现在一行中,以及辅助列表中的另一个单词是否也出现在同一行中。如果有,就打印出来。如果在以前的函数中,我只是用一个来检查一个,所以我不需要使用And运算符,我已经尝试了读取替代项,但是其他运算符不允许我达到我的条件 cleanLex中的lword(cleanLex是在readfiles.py中创建和填充的列表) 下面是显示函数的部分代码 Main.py: from collections import Counte

我的问题是在ifany()语句中需要有两个条件,这两个条件检查列表中的一个单词是否出现在一行中,以及辅助列表中的另一个单词是否也出现在同一行中。如果有,就打印出来。如果在以前的函数中,我只是用一个来检查一个,所以我不需要使用And运算符,我已经尝试了读取替代项,但是其他运算符不允许我达到我的条件

cleanLex中的lword(cleanLex是在readfiles.py中创建和填充的列表)

下面是显示函数的部分代码

Main.py:

from collections import Counter
from Categories.GainingAccess import GA
from Readfiles import *

# Speech Act Categories
CategoryGA = GA
# ----------------------

# Word hit counters
CategoryHits = []
LexiconHits = []
# ----------------------

# unsure if used at this point
cleansedLex = []
# ----------------------

# Lists to hold lines where words have been matched
matchedCatlines = []
matchedLexlines = []
TestLine = []


def languagemodel():
    for line in cleanChat.values():
        for lword in [cleanLex]:
            for cword in [CategoryGA]:
                for section in line:
                    if any(lword and cword in section for lword in
                           cleanLex and cword in CategoryGA):  # searches each section to find words matching words stored in cleanLex
                print("matched words %s and %s", "on line:    %s",
                      (lword, cword, section))


languagemodel()
回溯错误:

Traceback (most recent call last):
  File "C:/Users/Lewis Collins/Downloads/test/main.py", line 100, in <module>
    languagemodel()
  File "C:/Users/Lewis Collins/Downloads/test/main.py", line 89, in languagemodel
    cleanLex and cword in CategoryGA):  # searches each section to find words matching words stored in cleanLex
TypeError: 'bool' object is not iterable
回溯(最近一次呼叫最后一次):
文件“C:/Users/Lewis Collins/Downloads/test/main.py”,第100行,在
languagemodel()
文件“C:/Users/Lewis Collins/Downloads/test/main.py”,第89行,语言模型
CategoryGA中的cleanLex和cword):#搜索每个部分以查找与cleanLex中存储的单词匹配的单词
TypeError:“bool”对象不可编辑

关于如何绕过或解决此问题的任何建议。

类别中的cleanLex和cword
是一个难题。因此,当您在cleanLex中执行
lword,在CategoryGA中执行cword时,您正试图在bool上进行迭代。你希望这段代码做什么?
如果有的话(cleanLex中的lword和cword部分和CategoryGA中的cword部分)
:你认为这意味着什么?我个人认为它将要做的是,当它找到lword和cword部分,然后打印列表中的单词,我对此表示歉意,因为我似乎错过了问题中代码的打印声明try
如果有(cleanLex中的lword在第节中,cword在第节中,针对类别中的cword在类别中)
也许你的意思是:
如果有(cleanLex中的lword在第节中,针对类别中的cword)
cleanLex和cword在CategoryGA中是一个bool。因此,当您在cleanLex中执行
lword,在CategoryGA中执行cword时,您正试图在bool上进行迭代。你希望这段代码做什么?
如果有的话(cleanLex中的lword和cword部分和CategoryGA中的cword部分)
:你认为这意味着什么?我个人认为它将要做的是,当它找到lword和cword部分,然后打印列表中的单词,我对此表示歉意,因为我似乎错过了我在该问题中关于代码的打印声明try
如果有的话(对于分类中的cword,cleanLex中的lword在第节和cword在第节)
也许你的意思是:
如果有的话(对于分类中的cword,cleanLex中的lword在第节和cword在第节)