[Edu-sig] Using try / except: any stipulations against routine use?
Carl Cerecke
carl at free.org.nz
Mon Dec 19 23:19:49 CET 2011
I know I'm late to this discussion, but I tend to use something like:
if ext not in res_dict:
res_dict[ext] = 0
res_dict[ext] += 1
Cheers,
Carl.
On 16 December 2011 07:18, Christian Mascher <christian.mascher at gmx.de>wrote:
>
> On the other hand,
>>> res_dict[ext] = res_dict.get(ext, 0) + 1
>>>
>>> Isn't this at least as readable, and conceptually simpler?
>>
>> if ext in res_dict:
>> res_dict[ext] += 1
>> else: res_dict[ext] = 1
>>
>>
>
> I haven't done much coding in Python lately. And I found this much more
> readable than the .get method which I forgot about. I positively didn't
> understand the oneliner just by reading it over and over again.
>
> Of course I could easily have opened idle and looked up the .get method
> online (or looked in a manual).
>
> The really good thing about Python is that so much of the core language
> doesn't surprise you. One is able to write code which is understandable
> even to people with very little experience or to yourself after not coding
> in Python for years. Nobody has to write such clear-cut code all the time,
> but at least it is possible with very little effort.
>
> Christian
>
> ______________________________**_________________
> Edu-sig mailing list
> Edu-sig at python.org
> http://mail.python.org/**mailman/listinfo/edu-sig<http://mail.python.org/mailman/listinfo/edu-sig>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20111220/302c9932/attachment.html>
More information about the Edu-sig
mailing list