isnumeric (mhlib.py)

Morten Kjeldgaard mok at imsb.au.dk
Fri Jan 5 08:14:34 EST 2001


Steve Holden wrote:

>
> > I don't know what the meaning of isnumeric for mh is,
> > but why isn't numericprog simply like this:
> >
> > numericprog = re.compile('^[0-9]*$')
> >
> > Richard.
> >
> Again, if that will do for your purposes then go ahead and use it --
> although I suspect you might not want the empty string to be considered a
> number, in which case you might prefer the pattern to be
>
>     '^[0-9]+$'
>
> which will insist on seeing at least one digit.

... but this pattern excludes negative numbers, and positive numbers with an
explicit '+' sign in front. So

'^[+-]?[0-9]+$'

should be better.

/Morten

--
Morten Kjeldgaard                                | e-mail: mok at imsb.au.dk
Institute of Molecular and Structural Biology    | Phone : +45 89 42 50 26
Aarhus University                                | Fax   : +45 86 20 12 22
Gustav Wieds Vej 10, DK-8000 Aarhus C, Denmark   | Home  : +45 86 18 81 80






More information about the Python-list mailing list