[Tutor] file opening and errors.

Dan Klose dklose at nimr.mrc.ac.uk
Thu Oct 20 11:01:51 CEST 2005


Hi,

I usually use perl but fancy a bit of a change so have started playing
with python.

using perl to open a file or directory I usually use:

open(FILE, $file) or die "Error: $!\n";

The $! is a perl variable that holds an error should the open fail,
example being : "No such file or directory".

With python I have use a try except block but I have no idea how I would
get the same warning from python as I would from perl (the reason for
the exception), I am not even sure if this is possible (I assume it must
be) as google searching has been fruitless.

Thanks for any help, pointers and suggestions.

Dan.



More information about the Tutor mailing list