[Python-Dev] Re: stringobject question

M.-A. Lemburg mal@lemburg.com
Wed, 14 Jun 2000 10:43:45 +0200


Trent Mick wrote:
> 
> On Tue, Jun 13, 2000 at 10:53:58PM -0500, Al-Amerrho H. Amerin wrote:
> > Is this a bug or a feature?:
> >
> > Python 1.6a2 (#4, Jun  9 2000, 02:22:41)  [GCC 2.95.2 19991024
> > (release)] on linux2
> > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> > Copyright 1995-2000 Corporation for National Research Initiatives (CNRI)
> >
> > >>> ''.isdigit()
> > 1
> > >>> ''.isspace()
> > 1
> >
> 
> Good point, maybe. The __docs__ say:
> 
> "S.isdigit() -> int\n\
> \n\
> Return 1 if there are only digit characters in S,\n\
> 0 otherwise.";
> 
> static char isspace__doc__[] =
> "S.isspace() -> int\n\
> \n\
> Return 1 if there are only whitespace characters in S,\n\
> 0 otherwise.";
> 
> I am not an English language lawyer so I could see both interpretations from
> the doc strings. I agree, that the result with a zero length string is
> surprising.
> 
> Hi All,
> Which should it be? Sorry, if this has been covered.

I guess it's a bug... a subtle one though, because in a
certain sense both 1 and 0 are acceptable. But since
'' is considered to be false, I think that returning 0
makes more sense.

I'll fix this to return 0 for emtpy strings and Unicode objects.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/