[Python-Dev] bool conversion wart? (original) (raw)
Ben Wing ben at 666.com
Fri Feb 23 03🔞33 CET 2007
- Previous message: [Python-Dev] bool conversion wart?
- Next message: [Python-Dev] bool conversion wart?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2/22/07, Neal Becker <ndbecker2 at gmail.com> wrote:
Mike Klaas wrote: > On 2/22/07, Neal Becker <ndbecker2 at gmail.com> wrote: > >> Well consider this: >> >>>str (4) >> '4' >> >>>int(str (4)) >> 4 >> >>>str (False) >> 'False' >> >> >>>bool(str(False)) >> True >> >> Doesn't this seem a bit inconsisent? > > Virtually no python objects accept a stringified version of themselves > in their constructor: > >>>> str({}) > '{}' >>>> dict('{}') > Traceback (most recent call last): > File "", line 1, in > ValueError: dictionary update sequence element #0 has length 1; 2 is > required >>>> str([]) > '[]' >>>> list('[]') > ['[', ']'] > > Python is not Perl. > Except, all the numeric types do, including int, float, and complex. But not bool. In fact, this is not just academic. The fact that other numeric types act this way leaves a reasonable expectation that bool will. Instead, bool fails in the worst possible way: it silently gives a wrong result.
i agree with mike; it would just be asking for trouble. (have you ever been bitten by the Perl behavior where the string '0' is considered false? it's a nasty, nasty problem to debug.)
neal, you may be confusing the concepts of "convert data from one type to another" and "read the printed representation of data".
ben -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20070222/025eff8f/attachment.htm
- Previous message: [Python-Dev] bool conversion wart?
- Next message: [Python-Dev] bool conversion wart?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]