Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80708 > unrolled thread
| Started by | satishmlmlml@gmail.com |
|---|---|
| First post | 2014-11-13 14:32 -0800 |
| Last post | 2014-11-14 18:46 +1100 |
| Articles | 6 — 6 participants |
Back to article view | Back to comp.lang.python
How to recover bytes function? satishmlmlml@gmail.com - 2014-11-13 14:32 -0800
Re: How to recover bytes function? MRAB <python@mrabarnett.plus.com> - 2014-11-13 23:12 +0000
Re: How to recover bytes function? Chris Angelico <rosuav@gmail.com> - 2014-11-14 10:14 +1100
Re: How to recover bytes function? sohcahtoa82@gmail.com - 2014-11-13 15:16 -0800
Re: How to recover bytes function? Ben Finney <ben+python@benfinney.id.au> - 2014-11-14 10:37 +1100
Re: How to recover bytes function? Cameron Simpson <cs@zip.com.au> - 2014-11-14 18:46 +1100
| From | satishmlmlml@gmail.com |
|---|---|
| Date | 2014-11-13 14:32 -0800 |
| Subject | How to recover bytes function? |
| Message-ID | <44f58abf-35a8-4741-8b7c-7eabe99a326d@googlegroups.com> |
file = open('data.bin', 'rb')
bytes = file.read()
bytes
b'\x00\x00\x00\x02spam\x00\x03?\x9d\xf3\xb6'
records = [bytes([char] * 8) for char in b'spam']
TypeError: 'bytes' object is not callable
How to recover bytes function?
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-11-13 23:12 +0000 |
| Message-ID | <mailman.15793.1415920324.18130.python-list@python.org> |
| In reply to | #80708 |
On 2014-11-13 22:32, satishmlmlml@gmail.com wrote:
> file = open('data.bin', 'rb')
> bytes = file.read()
> bytes
> b'\x00\x00\x00\x02spam\x00\x03?\x9d\xf3\xb6'
> records = [bytes([char] * 8) for char in b'spam']
> TypeError: 'bytes' object is not callable
>
> How to recover bytes function?
>
The simple answer:
bytes = __builtins__.bytes
The smart answer:
Don't bind to 'bytes' in the first place!
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-11-14 10:14 +1100 |
| Message-ID | <mailman.15794.1415920478.18130.python-list@python.org> |
| In reply to | #80708 |
On Fri, Nov 14, 2014 at 9:32 AM, <satishmlmlml@gmail.com> wrote:
> file = open('data.bin', 'rb')
> bytes = file.read()
> bytes
> b'\x00\x00\x00\x02spam\x00\x03?\x9d\xf3\xb6'
> records = [bytes([char] * 8) for char in b'spam']
> TypeError: 'bytes' object is not callable
>
> How to recover bytes function?
del bytes
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | sohcahtoa82@gmail.com |
|---|---|
| Date | 2014-11-13 15:16 -0800 |
| Message-ID | <5caf79f5-85e3-49fc-88cf-410a580b9e5e@googlegroups.com> |
| In reply to | #80708 |
On Thursday, November 13, 2014 2:32:47 PM UTC-8, satish...@gmail.com wrote:
> file = open('data.bin', 'rb')
> bytes = file.read()
> bytes
> b'\x00\x00\x00\x02spam\x00\x03?\x9d\xf3\xb6'
> records = [bytes([char] * 8) for char in b'spam']
> TypeError: 'bytes' object is not callable
>
> How to recover bytes function?
So how many times do we have to ask you to tell us your EXPECTED output before you start actually doing that?
'bytes' is a built-in function, but built-in function definitions can be overwritten by redeclaring them. In this case, you're deleting the bytes function by assigning some read data to `bytes`. Don't do that. Either use a variable name other than 'bytes', or recover your bytes function.
-DJ
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-11-14 10:37 +1100 |
| Message-ID | <mailman.15796.1415921891.18130.python-list@python.org> |
| In reply to | #80708 |
satishmlmlml@gmail.com writes:
> file = open('data.bin', 'rb')
> bytes = file.read()
These are both terrible names, not least because they clobber the
built-in objects ‘file’ and ‘bytes’.
Don't name an object for *or not only for) its data type. Instead,
choose names that convey the *purpose* for the object.
--
\ “Alternative explanations are always welcome in science, if |
`\ they are better and explain more. Alternative explanations that |
_o__) explain nothing are not welcome.” —Victor J. Stenger, 2001-11-05 |
Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2014-11-14 18:46 +1100 |
| Message-ID | <mailman.15814.1415951174.18130.python-list@python.org> |
| In reply to | #80708 |
On 13Nov2014 14:32, satishmlmlml@gmail.com <satishmlmlml@gmail.com> wrote:
>file = open('data.bin', 'rb')
>bytes = file.read()
>bytes
>b'\x00\x00\x00\x02spam\x00\x03?\x9d\xf3\xb6'
>records = [bytes([char] * 8) for char in b'spam']
>TypeError: 'bytes' object is not callable
>
>How to recover bytes function?
The best way is not to use "bytes" for something else when you know you will be
using the builtin version as well. Using the same name for two things is
generally a bad idea.
The second, and worse, way is to see the documentation for the "builtins"
module.
Cheers,
Cameron Simpson <cs@zip.com.au>
Madness takes its toll. Please have exact change.
- Janice Hanes <janice@anv.net>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web