如果标题没有正确表示错误,请事先道歉。
我有一个名为ReadChat()的方法,我试图在名为SpeechActCounter()的方法中调用,如下所示 readfiles.py,其中存储了ReadChat():
import re
import os
Chatfile = 'ChatLogs/#####/Chat1.txt'
Lexfile = 'Lexicons/#####.txt'
def ReadChat():
with open (Chatfile) as file_read:
chat_content = file_read.readlines()
for linenum, line in enumerate(chat_content):
Cleanse = re.sub('<.*?>', '', line)
print(linenum, Cleanse)
file_read.close()
ReadChat()
def ReadLex():
with open (Lexfile) as file_read:
lex_content = file_read.readlines()
for line in lex_content:
lex_Cleanse = re.sub(r'^\d+[ \t]+\d+\.\d+%[ \t]*', '', line, flags=re.M)
lex_Cleanse = os.linesep.join([s for s in lex_Cleanse.splitlines() if s])
print(lex_Cleanse)
#ReadLex()
我不确定我在main.py
中的调用方法是否正确 main.py where SpeechActCounter() is stored
from collections import Counter
from Categories.GainingAccess import GA
from Readfiles import *
SpeechAct = ReadChat()
CategoryGA = GA
Hits = []
cleansedLex = []
def SpeechActCounter():
Word_Hit = None
with SpeechAct:
for line in SpeechAct:
if any(word in line for word in CategoryGA):
Word_Hit = False
for word in CategoryGA:
if line.find(word) != -1:
Word_Hit = True
Hits.append(word)
#print('%s appeared on Line' % (word))
count = Counter(Hits)
count.keys()
for key, value in count.items():
print(key, ':', value)
SpeechActCounter()
def LanguageDetect():
print('Hello')
#LanguageDetect()
以下是我运行程序时出现的错误
Traceback (most recent call last):
File "C:/Users/Lewis Collins/PycharmProjects/######main.py", line 31, in <module>
SpeechActCounter()
File "C:/Users/Lewis Collins/PycharmProjects/######/main.py", line 16, in SpeechActCounter
with SpeechAct:
AttributeError: __exit__