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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
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 number | Diff line number | Diff line change |
|---|
|
| 1 | +.. _documents: |
1 | 2 |
|
2 | 3 | Working with Documents |
3 | 4 | ========================== |
@@ -70,20 +71,24 @@ to (or aren't allowed to) interact with the file system. In practice this means |
70 | 71 | you can pass an open file or StringIO/BytesIO stream object to open or save |
71 | 72 | a document like so:: |
72 | 73 |
|
73 | | - f = open('foobar.docx') |
| 74 | + f = open('foobar.docx', 'rb') |
74 | 75 | document = Document(f) |
75 | 76 | f.close() |
76 | 77 |
|
77 | 78 | # or |
78 | 79 |
|
79 | | - with open('foobar.docx') as f: |
| 80 | + with open('foobar.docx', 'rb') as f: |
80 | 81 | source_stream = StringIO(f.read()) |
81 | 82 | document = Document(source_stream) |
82 | 83 | source_stream.close() |
83 | 84 | ... |
84 | 85 | target_stream = StringIO() |
85 | 86 | document.save(target_stream) |
86 | 87 |
|
| 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. |
87 | 92 |
|
88 | 93 | Okay, so you've got a document open and are pretty sure you can save it |
89 | 94 | somewhere later. Next step is to get some content in there ... |
Collapse file
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 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 |
52 | 52 | the end of the document. Paragraphs and tables added after calling this method |
53 | 53 | will appear in the new section:: |
54 | 54 |
|
55 | | - >>> current_section = document.section[-1] # last section in document |
| 55 | + >>> current_section = document.sections[-1] # last section in document |
56 | 56 | >>> current_section.start_type |
57 | 57 | NEW_PAGE (2) |
58 | 58 | >>> new_section = document.add_section(WD_SECTION.ODD_PAGE) |
|