Memoryview Methods
memoryview.tobytes()
Copy the logical contents of a view into immutable bytes. Default C order traverses the last dimension fastest; F order traverses the first dimension fastest. A order preserves physical order for contiguous storage and uses C order for noncontiguous input. None is equivalent to C. The result contains raw representation bytes, not text or a numeric conversion. For strided views the output excludes skipped elements. Unlike cast(), the result does not share mutable storage.
Formal Syntax & Structure
python syntaxpython
view.tobytes(order='C')Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| order | str | None | C, F, A, or None (default C). |
Return Value
bytes
Independent immutable snapshot of logical bytes.
Working Example
Example Snippetpython
view = memoryview(b"ABCDEF").cast("B", [2, 3])print(view.tobytes())print(view.tobytes("F"))print(memoryview(b"ABCDEF")[::2].tobytes())