Confused compare function :)

Neil Cerutti neilc at
Fri Dec 7 17:40:02 CET 2012

On 2012-12-07, Steven D'Aprano <steve+comp.lang.python at> wrote:
> On Thu, 06 Dec 2012 13:51:29 +0000, Neil Cerutti wrote:
>> On 2012-12-06, Steven D'Aprano
>> <steve+comp.lang.python at> wrote:
>>> total = 0
>>> for s in list_of_strings:
>>>     try:
>>>         total += int(s)
>>>     except ValueError:
>>>         pass  # Not a number, ignore it.
>> If it's internal data, perhaps. Of course, that would mean I
>> had the option of *not* creating that stupid list_of_strings.
> Not necessarily, it depends on the application.

I agree. I personally wouldn't want, e.g., 12.0 to get silently
skipped so I've never done this. I've never done anything like
that, but I can imagine it.

> If you have a spreadsheet, and create a formula =SUM(A1:A50)
> the expected behaviour is to just skip anything that is not a
> valid number, not raise an error. Sometimes correct
> application-level behaviour is to just ignore input that it
> doesn't care about.
> One of the things that I used to despise with a passion about
> MYOB is that if you clicked on the window outside of a button
> or field, it would scream at you "ERROR ERROR ERROR - that was
> not a button or field!!!!" That is to say, it would beep. I
> mean, *who fscking cares* that the user clicks in the window
> background? It's a harmless tick, like tapping your desk, just
> ignore it.

What happens in Word during a Mail Merge if an invalid field is
in the data file, one you don't even care about: You get to click
on a modular dialog box for every record you're merging with to
say IGNORE. And you can't quit.

> As a general rule, library functions should be strict about
> reporting errors, while applications may be more forgiving
> about errors that they don't care about. The "don't care about"
> part is important though -- your word processor shouldn't care
> about low level networking errors, but it should care if it
> can't save a file to a network drive. 

You have to draw the line somewhere in any case, and drawing it
all the way over to IGNORE is bound right some of the time. It
would be, I guess, Cargo Cult programming to never ignore errors.

Neil Cerutti

More information about the Python-list mailing list