On Sat, Jul 18, 2009 at 5:58 AM, Lie Ryan <lie.1...@gmail.com> wrote:

>
>
> If you're looking for speed, you should be aware that a failed
> try-clause is quite expensive in python and often (as in this case)
> codes using exception can be less readable than the one without since a
> program's flow in the case of exception is not linear (the non-linear
> execution is useful for quickly breaking out from nests of clauses, but
> not necessary in this case).


Was not aware that myself. Noted.


> Semantically, it is also wrong. Not finding the n'th prime in the cache
> is not really an exceptional case.
>
> If you insists on using a try-except clause, use it this way:
>
> Well, I don't have to use try-except. I think I got another idea though. I
could use an internal counter to keep track of how many prime numbers have
generated, and if not enough, generate more.

Thanks.

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to