Coercing one object to type of another
rosuav at gmail.com
Sat Feb 9 11:43:28 CET 2013
On Sat, Feb 9, 2013 at 9:29 PM, Vijay Shanker <deontics at gmail.com> wrote:
> Inside a function i get a two arguments, say arg1 and arg2, how can i convert arg2 to same type as arg1 ?
> I dont know type of arg1 or arg2 for that matter, I just want to convert arg2 to type of arg1 if possible and handle the exception if raised.
> but coerce('2',2) fails.If int('2') equals 2, why should it fail ?
You can get the type of any object, and call that:
More information about the Python-list