Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75718
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: TypeError: 'bytes' object is not callable error while trying to converting to bytes. |
| Date | 2014-08-05 15:57 +1000 |
| References | <02baad14-39b1-41a0-a47d-28772c97ea54@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12659.1407218248.18130.python-list@python.org> (permalink) |
Satish ML <satishmlwizpro@gmail.com> writes:
> >>>import struct
> >>>file = open('data.bin', 'rb')
Here you re-bind the name ‘file’ to the return value from that call.
> >>>bytes = file.read()
Here you re-bind the name ‘bytes’ to the return value from that call.
> >>> records = [bytes([char] * 8) for char in b'spam']
Here you attempt to call ‘bytes’, which (as the error says) is not
callable.
You should choose names which are not already bound::
in_file = open('data.bin', 'rb')
in_file_content = in_file.read()
records = [bytes([char] * 8) for char in in_file_content]
When choosing names, try to communicate the *purpose* of the value, its
semantic meaning. The type should be of secondary importance, and almost
always should not be part of the name.
--
\ “Institutions will try to preserve the problem to which they |
`\ are the solution.” —Clay Shirky, 2012 |
_o__) |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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