[Python-Dev] Re: stringobject question

Moshe Zadka Moshe Zadka <moshez@math.huji.ac.il>
Wed, 14 Jun 2000 11:46:48 +0300 (IDT)


On Wed, 14 Jun 2000, M.-A. Lemburg wrote:

> > > >>> ''.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.

I just realized something: if you change the semantics to mean "number of
digits", you'll get the right answer for all 0- and 1- length strings
and unicode objects.

just-an-observation-ly y'rs, Z.
--
Moshe Zadka <moshez@math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com