By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

would this be called bug?

P: n/a
The code is attached below. Basically I am taking a substring of
variable m, and using "buffer" instead of slicing.

However, the application of int on that buffer start correctly from
the offset, but it scans all the way to the end, instead of stopping
at the length of the buffer.

It works however, if I apply str function to output of buffer
function.

-A
(Pdb) m = "AA1234AA"
(Pdb) x = buffer(m, 2, 4)
(Pdb) x
<read-only buffer for 0x2a9d0c18a0, size 4, offset 2 at 0x2a9d0cb7f0>
(Pdb) int(x)
*** ValueError: invalid literal for int() with base 10: '1234AA'
(Pdb) m = "AA1234AA"
(Pdb) m = "AA1234"
(Pdb) x = buffer(m, 2, 4)
(Pdb) int(x)
1234
(Pdb)
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 24, 1:33 am, Amit Gupta <emaila...@gmail.comwrote:
The code is attached below. Basically I am taking a substring of
variable m, and using "buffer" instead of slicing.

However, the application of int on that buffer start correctly from
the offset, but it scans all the way to the end, instead of stopping
at the length of the buffer.

It works however, if I apply str function to output of buffer
function.

-A

(Pdb) m = "AA1234AA"
(Pdb) x = buffer(m, 2, 4)
(Pdb) x
<read-only buffer for 0x2a9d0c18a0, size 4, offset 2 at 0x2a9d0cb7f0>
(Pdb) int(x)
*** ValueError: invalid literal for int() with base 10: '1234AA'
(Pdb) m = "AA1234AA"
(Pdb) m = "AA1234"
(Pdb) x = buffer(m, 2, 4)
(Pdb) int(x)
1234
(Pdb)
Interestingly, if I try:

int(x, 10)

I get:

Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
int(x, 10)
TypeError: int() can't convert non-string with explicit base

Perhaps int(x) should also be complaining that x isn't a string.
Jun 27 '08 #2

P: n/a

"Amit Gupta" <em*******@gmail.comwrote in message
news:ab**********************************@u36g2000 prf.googlegroups.com...
| The code is attached below. Basically I am taking a substring of
| variable m, and using "buffer" instead of slicing.
|
| However, the application of int on that buffer start correctly from
| the offset, but it scans all the way to the end, instead of stopping
| at the length of the buffer.
|
| It works however, if I apply str function to output of buffer
| function.
|
| -A
|
|
| (Pdb) m = "AA1234AA"
| (Pdb) x = buffer(m, 2, 4)
| (Pdb) x
| <read-only buffer for 0x2a9d0c18a0, size 4, offset 2 at 0x2a9d0cb7f0>
| (Pdb) int(x)
| *** ValueError: invalid literal for int() with base 10: '1234AA'
| (Pdb) m = "AA1234AA"
| (Pdb) m = "AA1234"
| (Pdb) x = buffer(m, 2, 4)
| (Pdb) int(x)
| 1234
| (Pdb)

Just so you know, buffer() has been deprecated in 2.x and has been replaced
in Py3 by memoryview() (I believe) because others have had problems with
buffer().
Don't know any more.

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.