would this be called bug?

A

Amit Gupta

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)
 
M

MRAB

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.
 
T

Terry Reedy

| 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top