[docs] [issue25433] whitespace in strip()/lstrip()/rstrip()
Dimitri Papadopoulos Orfanos
report at bugs.python.org
Mon Jan 4 04:42:13 EST 2016
Dimitri Papadopoulos Orfanos added the comment:
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().
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25433>
_______________________________________
More information about the docs
mailing list