Try... except....Try again?

Xavier Ho contact at xavierho.com
Fri Jul 17 18:07:13 EDT 2009


On Sat, Jul 18, 2009 at 5:58 AM, Lie Ryan <lie.1296 at 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: contact at xavierho.com
Website: http://xavierho.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090718/9125440d/attachment.html>


More information about the Python-list mailing list