How to check if a string "is" an int?

Peter Otten __peter__ at web.de
Thu Dec 22 18:23:49 EST 2005


Steven D'Aprano wrote:

> But since you're going to take my protests about regexes more seriously
> than I intended you to, it is ironic that you supplied a regex that
> is nice and fast but doesn't work:

I think you said that "exceptions are cheap" elsewhere in this thread and
I read your post above as "regular expressions are slow". I meant to set
these statements into proportion.

Those who snip the Zawinski quote are doomed to demonstrate it in their
code, though it wouldn't have taken this lapse for me to grant you that
regexes are errorprone.

> BTW, you might find it informative to run timeit on the code snippet
> provided by Daniel before reflecting on the context of my "how slow"
> comment.

I'm getting about 10 usec for both cases, i. e. roughly the same as the
worstcase behaviour for try...except.

Peter



More information about the Python-list mailing list