import os
def get_strings(filename):
if not os.path.exists(filename):
print(f"ОШИБКА: Файл {filename} не найден в папке со скриптом!")
return set()
print(f"Читаю {filename}...")
strings = set()
try:
# Используем latin-1, она никогда не выдает ошибку чтения (в отличие от utf-8)
with open(filename, 'r', encoding='latin-1') as f:
for line in f:
clean_line = line.strip()
if len(clean_line) > 4:
strings.add(clean_line)
except Exception as e:
print(f"Не удалось прочитать файл {filename}: {e}")
return strings
def main():
clean_file = "clean.txt"
cheat_file = "cheat.txt"
output_file = "result.txt"
if not os.path.exists(clean_file) or not os.path.exists(cheat_file):
print("ОШИБКА: Убедись, что файлы clean.txt и cheat.txt лежат рядом со скриптом.")
else:
clean_set = get_strings(clean_file)
cheat_set = get_strings(cheat_file)
print("Сравниваю... это может занять время, если файлы огромные.")
diff = cheat_set - clean_set
try:
with open(output_file, 'w', encoding='utf-8') as f:
for string in sorted(diff):
f.write(string + '\n')
print(f"УСПЕХ! Найдено строк: {len(diff)}")
print(f"Результат в файле: {output_file}")
except Exception as e:
print(f"Ошибка при записи результата: {e}")
input("\nСкрипт завершил работу. Нажми Enter для выхода...")
if __name__ == "__main__":
main()