File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change 1+ .. _documents :
12
23Working with Documents
34==========================
@@ -70,20 +71,24 @@ to (or aren't allowed to) interact with the file system. In practice this means
7071you can pass an open file or StringIO/BytesIO stream object to open or save
7172a document like so::
7273
73- f = open('foobar.docx')
74+ f = open('foobar.docx', 'rb' )
7475 document = Document(f)
7576 f.close()
7677
7778 # or
7879
79- with open('foobar.docx') as f:
80+ with open('foobar.docx', 'rb' ) as f:
8081 source_stream = StringIO(f.read())
8182 document = Document(source_stream)
8283 source_stream.close()
8384 ...
8485 target_stream = StringIO()
8586 document.save(target_stream)
8687
88+ The ``'rb' `` file open mode parameter isn't required on all operating
89+ systems. It defaults to ``'r' `` which is enough sometimes, but the 'b'
90+ (selecting binary mode) is required on Windows and at least some versions of
91+ Linux to allow Zipfile to open the file.
8792
8893Okay, so you've got a document open and are pretty sure you can save it
8994somewhere later. Next step is to get some content in there ...
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ The :meth:`Document.add_section` method allows a new section to be started at
5252the end of the document. Paragraphs and tables added after calling this method
5353will appear in the new section::
5454
55- >>> current_section = document.section [-1] # last section in document
55+ >>> current_section = document.sections [-1] # last section in document
5656 >>> current_section.start_type
5757 NEW_PAGE (2)
5858 >>> new_section = document.add_section(WD_SECTION.ODD_PAGE)
You can’t perform that action at this time.
0 commit comments