This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author svenberkvens
Recipients svenberkvens
Date 2015-11-20.08:40:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1448008840.02.0.961643049915.issue25678@psf.upfronthosting.co.za>
In-reply-to
Content
Calling int() or long() on a buffer() object in Python 2.7 does not do the right thing. The following code snippet:

buf = buffer("123test", 1, 2)
print buf
print int(buf)

does not do what I would expect (that it print "23" twice). Instead, it prints "23" once and then throws an exception:

ValueError: invalid literal for int() with base 10: '23test'

This is caused by Objects/abstract.c function int_from_string(), which gets passed the length of the string but does not actually use that information to limit what part is parsed from the string. It only uses it to check for embedded NUL bytes. The real culprit is probably PyInt_FromString() which does not take a length indicator.
History
Date User Action Args
2015-11-20 08:40:40svenberkvenssetrecipients: + svenberkvens
2015-11-20 08:40:40svenberkvenssetmessageid: <1448008840.02.0.961643049915.issue25678@psf.upfronthosting.co.za>
2015-11-20 08:40:39svenberkvenslinkissue25678 messages
2015-11-20 08:40:39svenberkvenscreate