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 <rep...@bugs.python.org>
<http://bugs.python.org/issue25433>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to