Skip to content

Commit 6717686

Browse files
author
Steve Canny
committed
docs: small documentation fixes
1 parent 13dd6f0 commit 6717686

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

docs/user/documents.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.. _documents:
12

23
Working with Documents
34
==========================
@@ -70,20 +71,24 @@ to (or aren't allowed to) interact with the file system. In practice this means
7071
you can pass an open file or StringIO/BytesIO stream object to open or save
7172
a 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

8893
Okay, so you've got a document open and are pretty sure you can save it
8994
somewhere later. Next step is to get some content in there ...

docs/user/sections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The :meth:`Document.add_section` method allows a new section to be started at
5252
the end of the document. Paragraphs and tables added after calling this method
5353
will 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)

0 commit comments

Comments
 (0)