SHARE
TWEET

Untitled

a guest Jun 25th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top