Re: opening a file



cartercc wrote:

On Jan 14, 9:30 am, Chris Mattern <sys...@xxxxxxxxxxxxxx> wrote:
If you don't care whether the file opens, why are you opening it?

My point was that you can conjure up an exception for every rule.

In my job, I constantly write and run scripts that open and close
files. Many of these scripts are on-the-fly scripts. I've been at work
for three hours today, and already I've written two of these kinds of
scripts and have run around two dozen. Very rarely do I bother
checking the return value of open(), and I don't ever recall having an
open fail. The biggest problem I have is with typographical errors,
and warnings catch those.

I totally agree with error checking, and the scripts that I write for
others to run ALWAYS include this kind of error checking. The scripts
that I write FOR MYSELF for processing files rarely do, however,
because open() never fails and I'm too lazy to take the extra effort
(small though it may be) to type out the 'or die' clause. My quibble
is not with the rule, but with the idea that the rule has no
exceptions. Every rule has exceptions.

If it's any consolation, I am the only one that suffers the penalty
for not checking whether or not a file opens in my own scripts, and I
am perfectly willing to risk incurring the penalty to keep from typing
a few extra keystrokes with every invocation of open. This is a
deliberate choice on my part, and I have never sought to impose that
choice on anyone else.

CC

I suppose you're aware then, that if it did fail on a file that you did
need data from, that you would spend more than the 1 second a warn, die
or method you create to note the problem, and start digging through the
file, adding the checks, only when it does fail. If you didn't make a
typo and the file exists and is readable, then yeah, you'll probably
never have a problem. But, the same is true of checking the return.
You still would never have a problem and never see it die, warn or log
an error -- even if it silently ignores it (due to the return value)
and moves on fine, in a friendly manner. I couldn't imagine how it's
really saving any time at all by not adding a simple check. If
anything, create some very simple module or library and use that for
the open routines on all of your scripts, even if to just log and
happily and blindly move on (because yeah, sometimes it's okay to just
keep moving). Anyway, it's certainly up to you if it's just your code
and you affected.
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
.



Relevant Pages

  • Re: Python Scripts to logon to websites
    ... Thanks for your help with the search terms. ... Trying to make scripts that will open ... >> Does anyone have a simple example of a script that opens, say, gmail or ...
    (comp.lang.python)
  • Re: word opens without opening the document, like /n
    ... shortcut, ... I first noticed this behavior after running automation scripts. ... opens Word, opens a document, changes it, then closes Word. ... Do registry setting over ride command line switches? ...
    (microsoft.public.word.docmanagement)
  • Re: Opening multiple files at once, interface and flicker issues
    ... The first is to have opening scripts which should be triggered if the user navigates to them using the Window>> Show Window menu option. ... The second is to use FileMaker Advanced to actually remove the Window menu option thus preventing the user from opening those files. ... opens another file, the password is "inherited" and the second file's ...
    (comp.databases.filemaker)
  • Re: opening a file
    ... Many of these scripts are on-the-fly scripts. ... Every rule has exceptions. ... for not checking whether or not a file opens in my own scripts, ... deliberate choice on my part, and I have never sought to impose that ...
    (comp.lang.perl.misc)
  • Re: Constants for catch return values?
    ... negative response. ... The complex part of dealing with exceptions is not ... They consider it good programming practise to force ... We also don't want to bugger them to rewrite their scripts ...
    (comp.lang.tcl)