Skip to content
Advertisement

NameError: name ‘buffer’ is not defined

Python2 code:

x = buffer(chr(0) * 32)

What is the python3 equivalent? I tried to replace buffer with memoryview() but than name error becomes a type error: TypeError: memoryview: a bytes-like object is required, not ‘str’.

I’m pretty sure that this should be a string and not a byte.

Can someone help me?

Buffer function for python 3+ IS NOT THE ANSWER!

Advertisement

Answer

Adapting answers from Buffer function for python 3+

x = memoryview(b'x00'*32)`

memoryview expects bytes. Python 3 makes a distinction between bytes and strings now.

Advertisement