Advertisement
Guest User

Untitled

a guest
Feb 17th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1.  
  2. Part 1 walks the directory. Part 2 extracts the text I want. Each part works fine independently but all together it gives an error . I tried the code below but I get an unexpected indent error at the line starting: with open (fname)
  3.  
  4. import os
  5. import re
  6.  
  7. #walk the directory ree
  8. rootDir = '.'
  9. for dirName, subdirList, fileList in os.walk(rootDir):
  10. print('Found directory: %s' % dirName)
  11. for fname in fileList:
  12. print('\t%s' % fname)
  13.  
  14. #extract the text from each file
  15. with open(fname) as infile, open('out.txt', 'a') as outfile:
  16. full=infile.read().replace('\n','')
  17. text = ''.join(re.findall(r"START(.+?)END", full))
  18. outfile.write(text)
  19. infile.close()
  20. outfile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement