Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert memoryview to bytes?

How do I convert a Python memoryview to bytes?

For example:

>>> convert(memoryview(b"test"))
b"test"
like image 862
DrWhooze Avatar asked Nov 09 '18 16:11

DrWhooze


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.

like image 74
Bharel Avatar answered Sep 23 '22 19:09

Bharel