Вот мой код:
import re
with open("book.txt", "rb") as f:
s = re.sub(r'\s+', ' ', f.read().decode('WINDOWS-1251'), flags=re.M)
for s in re.split(r'(?<=[.!?…]) ', s):
print(s)
Вот что получаю:
The word bulldozer wandered through his mind for a moment in search 4 of something to connect with. The bulldozer outside the kitchen window was quite a big one. He stared at it. ”Yellow,” he thought and stomped off back to his bedroom to get dressed. Passing the bathroom he stopped to drink a large glass of water, and another. He began to suspect that he was hung over. Why was he hung over? Had he been drinking the night before? He supposed that he must have been. He caught a glint in the shaving mirror. ”Yellow,” he thought and stomped on to the bedroom.
w = open('booknew.txt', 'w')
booktext = str(booktext)
w.write(booktext)
w.close()
И вот что записывается в файл:
'\nThe word bulldozer wandered through his mind for a moment in search\n4\nof something to connect with', '\nThe bulldozer outside the kitchen window was quite a big one', '\nHe stared at it', '\x94Yellow,\x94 he thought and stomped off back to his bedroom\nto get dressed', '\nPassing the bathroom he stopped to drink a large glass of water, and\nanother', 'He began to suspect that he was hung over', 'Why was he hung\nover', 'Had he been drinking the night before', 'He supposed that he must\nhave been', 'He caught a glint in the shaving mirror', '\x94Yellow,\x94 he thought\nand stomped on to the bedroom', ...
Как мне изменить код, чтобы убрать все эти символы \n, \x94 and и такого рода ошибки "Arthur didn\x92t feel"? Нужно аккуратно записать предложения в файл для дальнейшей обработки. Спасибо.