← 返回首页
Update documents.rst by ibrahim-ogunbiyi · Pull Request #1514 · python-openxml/python-docx · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (1) All 1 file type selected Viewed files
Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show whitespace
Diff view
Unified
Split
Hide whitespace
Apply and reload
4 changes: 2 additions & 2 deletions docs/user/documents.rst
Show comments View file Edit file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ a document like so::
# or

with open('foobar.docx', 'rb') as f:
source_stream = StringIO(f.read())
source_stream = BytesIO(f.read())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

Hmm, interesting. I'm sure this is an artifact of this documentation being written during the Python 2 era, when StringIO actually meant "read bytes".

I'll put it on the shortlist and fix it up next time I'm in there.

document = Document(source_stream)
source_stream.close()
...
target_stream = StringIO()
target_stream = BytesIO()
document.save(target_stream)

The ``'rb'`` file open mode parameter isn't required on all operating
Expand Down
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.