Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
9fbbd3b8
Kaydet (Commit)
9fbbd3b8
authored
May 01, 2010
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Describe memoryview
üst
7de14ac0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
1 deletion
+53
-1
2.7.rst
Doc/whatsnew/2.7.rst
+53
-1
No files found.
Doc/whatsnew/2.7.rst
Dosyayı görüntüle @
9fbbd3b8
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
.. Fix accents on Kristjan Valur Jonsson, Fuerstenau
.. Fix accents on Kristjan Valur Jonsson, Fuerstenau
.. Big jobs: ElementTree 1.3, pep 391, sysconfig
, memoryview
.. Big jobs: ElementTree 1.3, pep 391, sysconfig
.. unittest test discovery
.. unittest test discovery
.. hyperlink all the methods & functions.
.. hyperlink all the methods & functions.
...
@@ -435,6 +435,58 @@ converter will change them to the standard :meth:`keys`,
...
@@ -435,6 +435,58 @@ converter will change them to the standard :meth:`keys`,
Backported to 2.7 by Alexandre Vassalotti; :issue:`1967`.
Backported to 2.7 by Alexandre Vassalotti; :issue:`1967`.
PEP 3137: The memoryview Object
====================================================
The :class:`memoryview` object provides a view of another object's
memory content that matches the :class:`bytes` type's interface.
>>> import string
>>> m = memoryview(string.letters)
>>> m
<memory at 0x37f850>
>>> len(m) # Returns length of underlying object
52
>>> m[0], m[25], m[26] # Indexing returns one byte
('a', 'z', 'A')
>>> m2 = m[0:26] # Slicing returns another memoryview
>>> m2
<memory at 0x37f080>
The content of the view can be converted to a string of bytes or to
a list of integers:
>>> m2.tobytes()
'abcdefghijklmnopqrstuvwxyz'
>>> m2.tolist()
[97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122]
>>>
:class:`memoryview` objects allow modifying the underlying object if
it's a mutable object.
>>> m2[0] = 75
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot modify read-only memory
>>> b = bytearray(string.letters) # Creating a mutable object
>>> b
bytearray(b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
>>> mb = memoryview(b)
>>> mb[0] = '*' # Assign to view, changing the bytearray.
>>> b[0:5] # The bytearray has been changed.
bytearray(b'*bcde')
>>>
.. seealso::
:pep:`3137` - Immutable Bytes and Mutable Buffer
PEP written by Guido van Rossum.
Implemented by Travis Oliphant.
Backported to 2.7 by Antoine Pitrou; :issue:`2396`.
Other Language Changes
Other Language Changes
======================
======================
...
...
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