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?
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to