GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — docs: small documentation fixes · python-openxml/python-docx@6717686

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/user
    • documents.rst
    • sections.rst
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/user/documents.rst‎

Copy file name to clipboardExpand all lines: docs/user/documents.rst
+7-2Lines changed: 7 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
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 ...
Collapse file

‎docs/user/sections.rst‎

Copy file name to clipboardExpand all lines: docs/user/sections.rst
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
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 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.