Posted By

NunAttack on 07/09/12


Tagged


Versions (?)

TextBlock


 / Published in: Python
 

URL: http://programthis.net/a-block-of-text/

First try by myself at anything biggish, kind of sucky

  1. import textwrap
  2. i = ''
  3. ns = ''
  4. secretword = 'Ring of Fire'
  5. fin = ''
  6. tw = textwrap
  7. f = open('theroadnottaken.txt') #Put the file name here!
  8. print 'The raw text is:\n'
  9. fr = f.read()
  10. print fr, '\n\n'
  11. f.close()
  12. fns = fr.replace(' ',"")
  13. fnsq = fns.replace("'", '')
  14. fnq = fnsq.replace('"', '')
  15. for line in fnq.split('\n'):
  16. if line.strip():
  17. ns += line + '\n'
  18.  
  19. print 'The condensed text is:\n', ns, '\n\n'
  20. mk = 0
  21. slen = len(ns)
  22. sit = slen / 24
  23. for secretword in range(0, sit): #This is a very shitty way of doing things.
  24. for i in ns[mk:slen]:
  25. fin = fin + i
  26. if len(fin) == 6:
  27. fin = fin + ('\n')
  28. elif len(fin) == 12:
  29. fin = fin + ('\n')
  30. elif len(fin) == 18:
  31. fin = fin + ('\n')
  32. elif len(fin) == 24:
  33. print '\nNEXT\n'
  34. mk = mk + len(fin)
  35. print fin
  36. fin = ''
  37. break

Report this snippet  

You need to login to post a comment.