[Python-checkins] CVS: python/dist/src/Objects abstract.c
Barry A. Warsaw
bwarsaw@cnri.reston.va.us
Thu, 10 Jun 1999 19:11:24 -0400 (EDT)
Update of /projects/cvsroot/python/dist/src/Objects
In directory anthem:/projects/python/develop/bwarsaw/src/Objects
Modified Files:
Tag: string_methods
abstract.c
Log Message:
int_from_string(): Removed. PyNumber_Int() now uses
PyInt_FromString().
float_from_string(): Removed. PyNumber_Float() now uses
PyFloat_FromString().
long_from_string(): Changes are best described by the comment above
the function
/* There are two C API functions for converting a string to a long,
* PyNumber_Long() and PyLong_FromString(). Both are used in builtin_long,
* reachable from Python with the built-in function long().
*
* The difference is this: PyNumber_Long will raise an exception when the
* string cannot be converted to a long. The most common situation is
* where a float string is passed in; this raises a ValueError.
* PyLong_FromString does not raise an exception; it silently truncates the
* float to an integer.
*
* You can see the different behavior from Python with the following:
*
* long('9.5')
* => ValueError: invalid literal for long(): 9.5
*
* long('9.5', 10)
* => 9L
*
* The first example ends up calling PyNumber_Long(), while the second one
* calls PyLong_FromString().
*/
The fact that builtin long takes an optional base is a new feature to
make it more compatible with string.atol().