Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f01cfd28
Commit
f01cfd28
authored
Jan 24, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add entry for io.BytesIO.getbuffer().
parent
0ddfd20a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
Doc/whatsnew/3.2.rst
Doc/whatsnew/3.2.rst
+29
-0
No files found.
Doc/whatsnew/3.2.rst
View file @
f01cfd28
...
...
@@ -992,6 +992,35 @@ implemented::
(Patch submitted by Daniel Urban; :issue:`5867`.)
io
--
The :class:`io.BytesIO` has a new method, :meth:`~io.BytesIO.getbuffer`, which
provides functionality similar to :func:`memoryview`. It creates an editable
view of the data without making a copy. The buffer's random access and support
for slice notation are well-suited to in-place editing::
import io
REC_LEN, LOC_START, LOC_LEN = 34, 7, 11
def change_location(buffer, record_number, location):
start = record_number * REC_LEN + LOC_START
buffer[start: start+LOC_LEN] = location
>>> byte_stream = io.BytesIO(
b'G3805 storeroom Main chassis '
b'X7899 shipping Reserve cog '
b'L6988 receiving Primary sprocket'
)
>>> buffer = byte_stream.getbuffer()
>>> change_location(buffer, 1, b'warehouse ')
>>> change_location(buffer, 0, b'showroom ')
>>> print(byte_stream.getvalue())
b'G3805 showroom Main chassis ' ->
b'X7899 warehouse Reserve cog ' ->
b'L6988 receiving Primary sprocket'
reprlib
-------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment