Re: quiet conversion functions

2006-04-13 Thread Sion Arrowsmith
Tim Chase <[EMAIL PROTECTED]> wrote: >def CFloat(value): > try: > value = float(value) > except (ValueError, TypeError): > value = 0 > return value >>> type(CFloat(None)) I think you want value = 0.0 . And you might also want to consider what errors

Re: quiet conversion functions

2006-04-12 Thread Carl Banks
Tim Chase wrote: > Is there some set of preexisting functions that do this sort > of "sensible" conversions without griping about crazy values > passed to them? No, because this isn't Perl. Seriously, it's a core principle of the Python language not to presume what a user considers to be "sensibl

Re: quiet conversion functions

2006-04-12 Thread Paul McGuire
"Tim Chase" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Are there existing "quiet" conversion functions? Kin of > int() and float()? > > My aim would be to call a function that would guarntee that > the result was of the defined typ

Re: quiet conversion functions

2006-04-12 Thread Robert Kern
Tim Chase wrote: > Are there existing "quiet" conversion functions? Kin of > int() and float()? Not in the standard library. Nor will there be. It goes against the development philosophy of the core Python development team. > My aim would be to call a function that would g

quiet conversion functions

2006-04-12 Thread Tim Chase
Are there existing "quiet" conversion functions? Kin of int() and float()? My aim would be to call a function that would guarntee that the result was of the defined type, choosing sensible defaults if needed. Example problems include: int("3.14") int(None) int(__bu