I have a .txt file called book.txt
that I want to divide into multiple .txt files (one per chapter). I would like to end up having .txt files whose names refer to those chapters. For example, if book.txt
has 20 chapters, I would end up with 1.txt
, 2.txt
, etc.
This is what I have so far:
import re
book = #I don't know how to import the book.txt file here
chapters = re.split("Chapter ", book, flags = re.IGNORECASE)
for chapter in chapters:
#Code to write a new .txt file with each element from the list I created using the number after 'Chapter' as the name for the .txt file.
As you can see, I'm stuck at importing my book.txt
file and at creating the new txt files. I'm fairly new to Python, so let me know if you need additional info.