Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Read Directory to get list of text files
- import os
- numdict = {"1": "One", "2": "Two", "3": "Three", "4": "Four", "5": "Five", "6": "Six",
- "7": "Seven", "8": "Eight", "9": "Nine", "14": "Fourteen", "150": "One Hundred and Fifty"}
- def num2word(s): # Replace this test function with your complete number-to-word process
- return numdict[s]
- cwdir = os.getcwd()
- dirlist = os.listdir()
- print(dirlist)
- for fname in dirlist:
- if fname.lower().endswith(".txt"):
- if fname.lower().endswith("-new.txt"):
- continue
- fin = open(fname)
- fsplit = fname.split(".")
- fout = open(fsplit[0] + "-new.txt", 'w')
- for x, fline in enumerate(fin):
- fline = fline.strip()
- lsplit = fline.split()
- if x == 0:
- book = ""
- if lsplit[0].isdigit():
- if lsplit[0] == "1":
- book = "First "
- if lsplit[0] == "2":
- book = "Second "
- if lsplit[0] == "3":
- book = "Third "
- lsplit = lsplit[1:]
- book += lsplit[0]
- book += " "
- book += num2word(lsplit[1])
- fout.write(book + "\n")
- print("\n" + book)
- continue
- verse = "Verse " + num2word(lsplit[0])
- verse += " "
- verse += " ".join(lsplit[1:])
- fout.write(verse + "\n")
- print(verse)
- fout.close()
- fin.close()
- # Output:
- #
- # First Corinthians Fourteen
- # Verse One Pursue love , yet ..
- # Verse Two For one who speaks ..
- # Verse Three But one who ..
- #
- # Acts One
- # Verse One The first account I composed..
- # Verse Two two until the day when..
- # Verse Three To these He also..
- #
- # Psalm One Hundred and Fifty
- # Verse One Praise the LORD ! Praise ..
- # Verse Two Praise Him for..
- # Verse Three Praise Him..
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement