perec.py 563 B

1234567891011121314151617181920212223
  1. import re
  2. source = open("scripts/frankenstein_gutenberg.txt", "r")
  3. #source = open("joyce.txt", "r")
  4. # destination = open("perec.txt", "w")
  5. regex = r'(\w*p+\w*e+\w*r+\w*e+\w*c+)'
  6. #regex = r'(\w*e+\w*l+\w*i+\w*f+\w*)'
  7. # destination.write("Source: George Orwell's 1984\n\n\n")
  8. # destination.write("Source: James Joyce, Almost complete works\n\n\n")
  9. sentences = []
  10. perec = ''
  11. for line in source:
  12. words = line.split(" ")
  13. for word in words:
  14. if re.search(regex, word):
  15. # print(word)
  16. perec+='<p>'+word+'</p>'
  17. # destination.write(word+'\n')
  18. print perec