[Tutor] Script performance: Filtering email

Sheila King sheila@thinkspot.net
Tue, 16 Jan 2001 19:49:40 -0800

On Tue, 16 Jan 2001 12:41:51 -0500, D-Man <dsh8290@rit.edu>  wrote about Re:
[Tutor] Script performance: Filtering email:

:On Tue, Jan 16, 2001 at 02:29:17AM -0800, Sheila King wrote:
:| On Tue, 16 Jan 2001 10:51:54 +0100, Remco Gerlich <scarblac@pino.selwerd.nl>
:| :Maybe you should wrap the whole thing in a try/except to log whatever
:| :goes wrong, like
:| :
:| :try:
:| :   (the body of your script)
:| :except:
:| :   import sys
:| :   f=open("somelogfile","w")
:                            ^
:Don't use "w" (write mode) here.  It will clobber the existing file.
:Use "a" (append mode) instead.  I would also suggest printing some
:text so that you know where the different errors are.  (see 3 lines
:farther for an examle)

Good tips. Thanks.

I have a question, about try/except blocks in general.
(I am assuming they come in pairs, like if/else, right?)

If I put

    (body of my script)

and suppose the script tries to connect to the SMTP server, but fails, will it
try more than once? Or it tries once, then gives up, and raises an exception?
How many times does "try" try until it gives up? Once? Several times? If I had
some code that was supposed to execute, like it needed to connect to some
server, and for some reason that server was not available for connection, so
it raised an error, how would I keep the script running and trying to connect
to that server later?

Sheila King