如何修复多处理器类型错误:'list'对象不可调用



这段代码在www.thesarus.com上的一个列表中迭代以获取同义词……我将其划分为不同的多处理器以使其更快。

def pri():
return emotions
ok = pri()
skipped =  []
def emo(numb, max):
while numb <= max:
try:
words = ok[numb]
URL = 'https://www.thesaurus.com/browse/'+words.word+"?s=t"
page = requests.get(URL)
soup = BeautifulSoup(page.content,'html.parser')
result = soup.find(class_="css-11nwwws e1gu66k41")
try:
n = result.text
nws = n.split('S')
nwn = nws[1].split('N') 
lonwn = len(nwn[0])
more =[]
repeat = False
for i in nwn[0]:
trial = nwn[0]
total = len(nwn[0])
if i not in more:
more.append(i)
elif i == trial[total-1:]:
repeat = False
break
else:
repeat =True
break
if repeat == True:
la = lonwn-2
gnwn = nwn[0]
number = int(gnwn[la:])
else:
la = lonwn-1
gnwn =nwn[0]
number = int(gnwn[la:])
while number != 0:
if not ConnectionError == True:
URL = 'https://www.thesaurus.com/browse/'+words.word+"?s=t"
page = requests.get(URL)
soup = BeautifulSoup(page.content,'html.parser')
result = soup.find(class_="css-11nwwws e1gu66k41")
try:
definition = soup.find_all("a",class_="css-1wndipq eh475bn1")
for define in definition:
if define.text not in words.array:
emotions[numb].array.append(define.text)
else:
continue
except AttributeError:
URL ='https://www.thesaurus.com/browse/'+words.word+'/'+str(number)
page= requests.get(URL)
soup = BeautifulSoup(page.content,'html.parser')
try:
definition = soup.find_all("a",class_="css-1wndipq eh475bn1")
for define in definition:
if define.text not in words.array:
emotions[numb].array.append(define.text)
else:
continue
except AttributeError:
pass
else:
print("Connection error could not get emotion", emotions[numb].word)
number-=1
URL ='https://www.thesaurus.com/browse/'+emotions[numb].word+'/'+str(number)
if number <=1:
break
except AttributeError:
error = emotions[numb].word
skipped.append(error)
pass
except TypeError:
pass
numb +=1

p = Process(target=emo, args=(0,50))
p6 = Process(target=emo, args=(51,100))
p1 = Process(target=emo, args=(101,150))
p2 = Process(target=emo, args=(151,200))
p3 = Process(target=emo, args=(201,251))
p4 = Process(target=emo, args=(251,300))
p5 = Process(target=emotions, args=(301,321))
if __name__ == "__main__":
print("Training Bot, please wait")
p.start()
p6.start()
p1.start()
p2.start()
p3.start()
p4.start()
p5.start()
p.join()
p1.join()
p2.join()
p3.join()
p4.join()
p6.join()
p5.join()
if len(skipped) >0:
print("Sadly the computer could not get the right definition and synonyms for the some emotions, would you like to help (y/n)n")
ask = input("Me:")
if ask.lower == "y":
where = 0
for i in skipped:
for emo in emotions:
where+=1
if i == emo:
break
print("Please go to " + 'https://www.thesaurus.com/browse/'+emotions[where]  + ". and copy and paste all the synonyms for" + i)
print("Please be careful because that will be how we train the bot.")
print("input listn")
ask = input("Me: ")
for li in ask:
emotions[where].array.append(li)
print("Done training Bot")
print("Welcome to Advice Bot. Program will start and when ever your ready for it to end. type quit.")
cont = True
print("How have you been lately?")

但在运行时发生了这种情况:

Training Bot, please wait
Process Process-7:
Traceback (most recent call last):
File "C:UsersNnajiAppDataLocalProgramsPythonPython39libmultiprocessingprocess.py", line 315, in _bootstrap
self.run()
File "C:UsersNnajiAppDataLocalProgramsPythonPython39libmultiprocessingprocess.py", line 108, in run
self._target(*self._args, **self._kwargs)
TypeError: 'list' object is not callable

我尝试添加一个try/except TypeError,看看它是否会被捕获,然后继续前进,而不暂停程序。但这并没有奏效。我没有更多的想法。

编辑原来我犯了一个错误,把情绪而不是表情放进去,所以计算机试图调用列表情绪,而不是函数emo

替换

p5 = Process(target=emotions, args=(301,321))

带有

p5 = Process(target=emo,args=(301,321))

相关内容

最新更新