I have a text file that constitutes a "database" of Pokemon information, formatted like so:
Bulbasaur ๐๐ฟ๐ฎ๐๐๐ ๐ฃ๐ผ๐ถ๐๐ผ๐ป๐งช
Ivysaur ๐๐ฟ๐ฎ๐๐๐ ๐ฃ๐ผ๐ถ๐๐ผ๐ป๐งช
Venusaur ๐๐ฟ๐ฎ๐๐๐ ๐ฃ๐ผ๐ถ๐๐ผ๐ป๐งช
Charmander ๐๐ถ๐ฟ๐ฒ๐ฅ
... and so on.
What I would like to do is turn this text file into 1025 different text files (one for each line), with each text file named the first word of the line (eg Bulbasaur.txt, Ivysaur.txt).
It seems like this isn't something I can accomplish with Notepad++ alone, and I've searched here and seen some answers that suggest Python code, which tends to look something roughly like this:
with open("text_file.txt") as f:
for i, line in enumerate(f):
with open(f"{i+1}.txt", "w") as g:
g.write(line)
All of the answers I've seen are designed in such a way that the text files are named according to the line number, though (eg 0001.txt, 0002.txt), and I need the filenames to be the first word of each line. I'm not a programmer and I'm not familiar at all with Python; what would I have to do to pull this off?
Thank you!
You can use the string split()
function to split text into separate words.
with open("text_file.txt") as f:
for line in f:
parts = line.split()
name = parts[0]
with open(f"{name}.txt", "w") as g:
g.write(line)