Help catching error message

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Nov 8 21:57:28 EST 2011


On Tue, 08 Nov 2011 17:48:57 -0800, Gnarlodious wrote:

> On Nov 8, 3:16 pm, Steven D'Aprano wrote:
> 
>> content = Data.Dict.SaveEvents(Data.Plist.Events) or content
>>
>> This will leave content unchanged if no error is returned, otherwise it
>> will replace the value.
> Ah, the 'or' operator does it. Thank you, that is exactly what I was
> looking for.
> 
> I should confess, I am not a programmer and don't even know what
> "idiomatic" means in this context. I don't know Java or PHP, only a
> little Forth from the HP calculator era. Advanced topics I just skip
> over because I don't understand them. But I am learning slowly and
> appreciate the help.

Idiomatic in this context means that the code follows standard styles, 
patterns or techniques commonly accepted by most good programmers of the 
language. This implies that the code works with the language, playing to 
its strengths, rather than against it.

Non-idiomatic code tends to be slower than it could be, or harder to 
read, or harder to maintain, or all three. Idiomatic is relative to the 
language: what is idiomatic for one language may not be for another.

For instance, if I were to ask "How do I do something with each item of a 
list?", the idiomatic way in Python would be:


for item in some_list:
    do_something_with(item)


rather than:

for i in range(len(some_list)):
    item = some_list[index]
    do_something_with(item)

and especially not this:

index = 0
while index < len(some_list):
    item = some_list[index]
    do_something_with(item)
    index += 1



Regards,



-- 
Steven



More information about the Python-list mailing list