Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import docx, os, glob
  2. finaldocname = 'Midterm-All-Questions.docx'
  3. finaldoc=docx.Document()
  4. docstoworkon = glob.glob('*.docx')
  5. if finaldocname in docstoworkon:
  6. docstoworkon.remove(finaldocname) #dont process final doc if it exists
  7.  
  8. for f in docstoworkon:
  9. doc=docx.Document(f)
  10.  
  11. fullText=[]
  12. for para in doc.paragraphs:
  13. fullText.append(para.text) #generates a long text list
  14.  
  15. # finaldoc.styles = doc.styles
  16. for l in fullText:
  17. # if l=='u'\n'':
  18. if '#' in l:
  19. print('We got here!')
  20. if '#1 ' not in l: #check last two characters to see if this is the first question
  21. finaldoc.add_section() #only add a page break between questions
  22. finaldoc.add_paragraph(l)
  23. # finaldoc.add_page_break
  24. # finaldoc.add_page_break
  25. finaldoc.save(finaldocname)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement