Coercing two numbers without coerce()
Luciano Ramalho
luciano at ramalho.org
Wed Dec 10 17:27:13 EST 2014
Python 3 dropped the coerce() built-in, but I have a situation where
I'd love to use it.
I have two numbers A, B and I need to get the value of A coerced to
the type of A+B. This is for a generator function that will produce a
series similar to what itertools.count does.
I know I can do type(A+B)(A), or A+B-B, but both alternatives are ugly
and perform needless arithmetic.
What do you suggest, now that the coerce() built-in is not available?
Cheers,
Luciano
--
Luciano Ramalho
Twitter: @ramalhoorg
Professor em: http://python.pro.br
Twitter: @pythonprobr
More information about the Python-list
mailing list