Message257449
In Python 2, as far as I can understand, string.whitespace and str.isspace() are different:
* str.isspace() is built upon the C isspace() function and is therefore locale-dependant. Python heavily relies on isspace() to detect "whitespace" characters.
* string.whitespace is a list of "ASCII whitespace characters" carved in stone. As far as I can see string.whitespace is defined but not used anywhere in Python source code.
See source code:
* Modules/stringobject.c around line 3319:
[...]
string_isspace(PyStringObject *self)
{
[...]
e = p + PyString_GET_SIZE(self);
for (; p < e; p++) {
if (!isspace(*p))
return PyBool_FromLong(0);
}
return PyBool_FromLong(1);
[...]
* Lib/string.py near line 23:
whitespace = ' \t\n\r\v\f'
Functions strip()/lstrip()/rstrip() use str.isspace() and have nothing to do with string.whitespace:
* Modules/stringobject.c around line 1861:
[...]
do_strip(PyStringObject *self, int striptype)
{
[...]
i = 0;
if (striptype != RIGHTSTRIP) {
while (i < len && isspace(Py_CHARMASK(s[i]))) {
i++;
}
}
[...]
Therefore I suggest the documentation of Python 2.7 points to str.isspace() wherever the term "whitespace" is used in the documentation - including this specific case of strip()/lstrip()/rstrip(). |
|
Date |
User |
Action |
Args |
2016-01-04 09:42:13 | Dimitri Papadopoulos Orfanos | set | recipients:
+ Dimitri Papadopoulos Orfanos, ezio.melotti, docs@python |
2016-01-04 09:42:13 | Dimitri Papadopoulos Orfanos | set | messageid: <1451900533.26.0.027212012044.issue25433@psf.upfronthosting.co.za> |
2016-01-04 09:42:13 | Dimitri Papadopoulos Orfanos | link | issue25433 messages |
2016-01-04 09:42:12 | Dimitri Papadopoulos Orfanos | create | |
|