On May 24, 1:33 am, Amit Gupta <[EMAIL PROTECTED]> wrote: > 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. -- http://mail.python.org/mailman/listinfo/python-list