How to convert memoryview to bytes?

Viewed 10013

How do I convert a Python memoryview to bytes?

For example:

>>> convert(memoryview(b"test"))
b"test"
1 Answers

Python's memoryview has a tobytes() method that allows you to do just that. You're also able to call bytes() on the object.

Keep in mind that converting a memoryview object to bytes copies the data, and you're able to use memoryview in most places either way. I wouldn't suggest you to convert.

Related