On 7 July 2013 06:14, Joshua Landau <joshua.landau...@gmail.com> wrote: > On 7 July 2013 05:48, Steven D'Aprano > <steve+comp.lang.pyt...@pearwood.info> wrote: >> On Sun, 07 Jul 2013 05:17:01 +0100, Joshua Landau wrote: >> >>> On 7 July 2013 04:56, Steven D'Aprano >>> <steve+comp.lang.pyt...@pearwood.info> wrote: >> ... >>>> def promote(x): >>>> if isinstance(x, str): raise TypeError return float(x) >> >>>>>> from operator import methodcaller >>>>>> safe_float = methodcaller("__float__") >> >> Nice! >> >> That's almost as fast as calling float. That will probably do :-) > > *Almost* as fast? > *incorrect timings* > > Actually, it's a fair bit faster (yes, I am purposely not showing you > the results for Decimals).
*sigh*, it seems that was just because it's slower to access __builtins__ than globals(). float() is maybe 2% faster if you fix that. -- http://mail.python.org/mailman/listinfo/python-list