File tree 1 file changed +8
-10
lines changed
1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change 12
12
if __name__ == '__main__' :
13
13
try :
14
14
document = opendocx (sys .argv [1 ])
15
+ newfile = open (sys .argv [2 ],'w' )
15
16
except :
16
- print ('Please supply a filename . For example:' )
17
- print (''' example-extracttext.py 'My Office 2007 document.docx' ''' )
17
+ print ('Please supply an input and output file . For example:' )
18
+ print (''' example-extracttext.py 'My Office 2007 document.docx' 'outputfile.txt' ' '' )
18
19
exit ()
19
20
## Fetch all the text out of the document we just created
20
21
paratextlist = getdocumenttext (document )
21
22
22
- # Note that if using shell redirection &>, 1> 2> etc) Python tries to
23
- # change the unicode into ASCII and fails - even with a UTF-8 $LANG
24
- # As a workaround, create our own ASCII copy of the list.
25
- asciiparatextlist = []
23
+ # Make explicit unicode version
24
+ newparatextlist = []
26
25
for paratext in paratextlist :
27
- asciiparatextlist .append (paratext .encode ("ascii" , "backslashreplace" ))
26
+ newparatextlist .append (paratext .encode ("utf-8" ))
28
27
29
28
## Print our documnts test with two newlines under each paragraph
30
- print '\n \n ' .join (paratextlist )
31
-
32
-
29
+ newfile .write ('\n \n ' .join (newparatextlist ))
30
+ #print '\n\n'.join(newparatextlist)
You can’t perform that action at this time.
0 commit comments