TypeError: 'bytes' object is not callable error while trying to converting to bytes.
Satish ML
satishmlwizpro at gmail.com
Tue Aug 5 01:47:51 EDT 2014
Hi,
>>>import struct
>>>file = open('data.bin', 'rb')
>>>bytes = file.read()
>>> records = [bytes([char] * 8) for char in b'spam']
Traceback (most recent call last):
File "<pyshell#99>", line 1, in <module>
records = [bytes([char] * 8) for char in b'spam']
File "<pyshell#99>", line 1, in <listcomp>
records = [bytes([char] * 8) for char in b'spam']
TypeError: 'bytes' object is not callable
If we code something like given below, it works.
>>> records = [([char] * 8) for char in b'spam']
>>> records
[[115, 115, 115, 115, 115, 115, 115, 115], [112, 112, 112, 112, 112, 112, 112, 112], [97, 97, 97, 97, 97, 97, 97, 97], [109, 109, 109, 109, 109, 109, 109, 109]]
Could you kindly help me resolve this problem of converting to bytes?
More information about the Python-list
mailing list