Я пытался отправить значения между каждой функцией.Я создал код:
def filter(thread, i):
text = "NAME".lower()
has_good = False
positive_keywords = i
for ch in ['&', '#', '“', '”', '"', '*', '`', '*', '’', '-']:
if ch in text:
text = text.replace(ch, "")
sentences = [text]
def check_all(sentence, ws):
return all(re.search(r'\b{}\b'.format(w), sentence) for w in ws)
for sentence in sentences:
if any(check_all(sentence, word.split('+')) for word in positive_keywords):
has_good = True
break
if not has_good:
sys.exit()
def testscript(thread, i):
filter(thread, i)
def script():
old_list = []
old_names_list = []
while True:
new_names_list = [line.rstrip('\n') for line in open('names.txt')]
for new_thread in get_random_names(): #A function that contians 100 random names
if not new_names_list == old_names_list:
for i in new_names_list:
if not i in old_names_list:
threading.Thread(target=testscript, args=(new_thread, i)).start()
old_names_list = new_names_list
elif new_thread not in old_list: #If the names are not added in old_list. start new thread.
threading.Thread(target=testscript, args=(new_thread,)).start()
old_list.append(new_thread)
else:
randomtime = random.randint(1, 3)
time.sleep(randomtime)
Итак, что код выглядит следующим образом: он начинается с помощью script ().Он проверяет, увеличился ли мой txt-файл и имеет ли он значение threading.Thread(target=testscript, args=(new_thread, i)).start()
- если он не находит ничего в текстовом файле, он должен выполнить elif new_thread not in old_list:
Однако моя проблема сейчасчто в elif оно не содержит имени (в нашем случае это I), а в if not new_names_list == old_names_list:
оно содержит i.Это означает, что мне нужно отправить i
иногда, а иногда нет.Проблема в том, когда нет имени.Это даст мне ошибку missing 1 required positional argument: 'i'
, и это из-за отсутствия имени.Как я могу быть в состоянии отправить значение в поток, если нет значения этого?