Exception as the primary error handling mechanism?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Jan 6 16:50:29 CET 2010

Phlip a écrit :
> On Jan 5, 8:49 pm, Steven D'Aprano
> <ste... at REMOVE.THIS.cybersource.com.au> wrote:
>>> (A related question - why can't I just go 'if record = method():  use
>>> (record)'. Why extra lines just to trap and assign the variable before
>>> using it?)
>> Because that idiom is responsible for probably the most common error in C
>> of all, at least one of the most common errors. Thank goodness Python
>> forbids such a dangerous construct.
> switching = for == is the "most common error in C"?
> I can't tell if you are joking.

It's at least a _very_ common error in all languages that allow this 
construct. In C, it's common enough to gave birth to the "BestPractice" 
you described, ie swapping operand orders in equality test to have the 
compiler detect the problem - at least when one of the operand is a 
function call expression or constant (it obviously won't 'work' when 
both operands are variables).

Anyway: in Python, assignment is not an expression, and this isn't going 
to change anytime soon.

More information about the Python-list mailing list