A little disappointed so far

Donn Cave donn at u.washington.edu
Mon May 19 13:39:11 EDT 2003


Quoth Alex Martelli <aleax at aleax.it>:
| 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.

Does Perl also have an equivalent to IOError's 'filename' attribute?
I think that's a mighty good thing.  At least with the information
stored somewhere, you could further reduce to

   die "$!"

consider something like

   authenticate_with_Kerberos() || die "$!"

and imagine how useful it would be to know what file they mean with
"Can't open file".

	Donn Cave, donn at u.washington.edu




More information about the Python-list mailing list