I love assert

Marko Rauhamaa marko at pacujo.net
Wed Nov 12 18:31:21 EST 2014


Chris Angelico <rosuav at gmail.com>:

> On Thu, Nov 13, 2014 at 10:23 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> However, the programmer could have played this frustration out already
>> in his head and written:
>>
>>      assert len(choices) > 0
>>      count = next_size / len(choices)
>
> assert choices
> count = next_size / len(choices)
>
> Or even just:
>
> count = next_size / len(choices) # choices won't be empty

Precisely.


Marko



More information about the Python-list mailing list