Map object has no len() in Python 3 Map object has no len() in Python 3 python-3.x python-3.x

Map object has no len() in Python 3


In Python 3, map returns an iterator. If your function expects a list, the iterator has to be explicitly converted, like this:

data = list(map(...))

And we can do it simply, like this

with open(args[0], "rb") as input_file:    data = list(input_file.read())

rb refers to read in binary mode. So, it actually returns the bytes. So, we just have to convert them to a list.

Quoting from the open's docs,

Python distinguishes between binary and text I/O. Files opened in binary mode (including 'b' in the mode argument) return contents as bytes objects without any decoding.