A little disappointed so far
Alex Martelli
aleax at aleax.it
Mon May 19 03:38:51 EDT 2003
Brian Quinlan wrote:
>> BTW,
>> open ($file) || die "Couldn't open $file"
>> strikes me as rather readable. And concise.
>
> In Python, just write:
> f = open(file)
>
> If there is an exception, an error message will be generated explaining
> why the file could not be opened and your script will terminate.
>
> The problem with your Perl code is that it doesn't really help with
> problem diagnosis i.e. does the file not exist, is it a directory, do I
> not have the necessary permissions, etc.
That's just because the die statement's argument above isn't using the
normal idiomatic Perl form, which would be:
die "Couldn't open data file $file: $!"
where the $! gives the details of the error. Not Perl's fault for
once -- it's just as possible to erroneously and anti-idiomatically
omit printing the error details in a Python except clause.
Alex
More information about the Python-list
mailing list