Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75717

TypeError: 'bytes' object is not callable error while trying to converting to bytes.

Newsgroups comp.lang.python
Date 2014-08-04 22:47 -0700
Message-ID <02baad14-39b1-41a0-a47d-28772c97ea54@googlegroups.com> (permalink)
Subject TypeError: 'bytes' object is not callable error while trying to converting to bytes.
From Satish ML <satishmlwizpro@gmail.com>

Show all headers | View raw


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?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

TypeError: 'bytes' object is not callable error while trying to converting to bytes. Satish ML <satishmlwizpro@gmail.com> - 2014-08-04 22:47 -0700
  Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes. Ben Finney <ben+python@benfinney.id.au> - 2014-08-05 15:57 +1000
  Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes. Chris Angelico <rosuav@gmail.com> - 2014-08-05 15:57 +1000
  Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes. Travis Griggs <travisgriggs@gmail.com> - 2014-08-05 22:31 -0700
  Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes. Chris Angelico <rosuav@gmail.com> - 2014-08-06 15:37 +1000

csiph-web