Author Dimitri Papadopoulos Orfanos
Recipients Dimitri Papadopoulos Orfanos, docs@python, ezio.melotti
Date 2016-01-04.09:42:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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/ 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]))) {

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:13Dimitri Papadopoulos Orfanossetrecipients: + Dimitri Papadopoulos Orfanos, ezio.melotti, docs@python
2016-01-04 09:42:13Dimitri Papadopoulos Orfanossetmessageid: <>
2016-01-04 09:42:13Dimitri Papadopoulos Orfanoslinkissue25433 messages
2016-01-04 09:42:12Dimitri Papadopoulos Orfanoscreate