Resume after exception
Dan Sommers
me at privacy.net
Tue Jun 14 07:59:31 EDT 2005
On Tue, 14 Jun 2005 10:09:30 +0100,
"Richard Lewis" <richardlewis at fastmail.co.uk> wrote:
> Hi there,
> Is it possible to have an 'except' case which passes control back to the
> point after the exception occurred?
Not that I can think of.
[ example of "interrupting" a file-reading function in order to ask the
user if they really want to read a locked file ]
I would rewrite that this way (untested, and without error checking):
def open_file(file_name, read_if_locked=False):
f = file(file_name)
[read first line]
if first_line == "FILE LOCKED" and read_if_locked == FALSE:
return False
[read the rest]
return True
def open_command():
if open_file("foo.bar") == False:
[ask the user what to do]
if ans == tkMessageBox.YES:
open_file("foo.bar", True )
Regards,
Dan
--
Dan Sommers
<http://www.tombstonezero.net/dan/>
More information about the Python-list
mailing list