[EMAIL PROTECTED] writes:
> In real life, I want to set some return values to sensible defaults
> if the file doesn't exist, but I want the errors from inside the
> block to trickle up as normal.
Sure. Just be careful only to catch the exceptions that you do want to
handle at that level of the co
Those are some good responses, but I think they focused a little too
much on the specifics of my example - especially the 'print'
statement. In real life, I want to set some return values to sensible
defaults if the file doesn't exist, but I want the errors from inside
the block to trickle up as no
Scott David Daniels <[EMAIL PROTECTED]> writes:
> Actually, this will be followed by some foolishness because
> (1) [the "print" format argument was wrong]
> and
> (2) [the code attempts to loop over the failed input file anyway]
You're right. Shame on me for posting untested code snippets, Thank
In message <[EMAIL PROTECTED]>, Carl
Banks wrote:
> Consider this: is there any other code in your program that has to do
> something different based on whether you successfully opened this file
> or not? If so, how will you notify it whether the call has succeeded
> or not? Very often, the call
Ben Finney wrote:
> [EMAIL PROTECTED] writes:
> ... try to only catch exceptions from the
> minimum amount of code that does one discrete action.
>
> try:
> input_file = open(my_filename)
> except IOError, exc:
> print "Can't open myfile: %(exc)" % locals()
>
> for lin
[EMAIL PROTECTED] writes:
> try:
> for line in open(myFileName):
> count += openAndProcessSubfile(line)
> except IOError:
> print "Can't open myfile"
>
> ... now the 'except' incorrectly catches errors from
> openAndProcessSubfile.
So don't include it. You've discovered a good pr
On Aug 27, 5:35 pm, [EMAIL PROTECTED] wrote:
> I have:
>
> try:
> for line in open(myFileName):
> count += 1
> except IOError:
> print "Can't open myfile"
>
> (I know, this is bad, I never close the file, but its just for
> illustration). But then I change it to:
>
> try:
> for
In message <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> try:
> for line in open(myFileName):
> count += 1
> except IOError:
> print "Can't open myfile"
>
> (I know, this is bad, I never close the file, but its just for
> illustration).
No, that's fine. The file object returne
[EMAIL PROTECTED] wrote:
> I have:
>
> try:
> for line in open(myFileName):
> count += 1
> except IOError:
> print "Can't open myfile"
>
> (I know, this is bad, I never close the file, but its just for
> illustration). But then I change it to:
>
> try:
> for line in open(myF
I have:
try:
for line in open(myFileName):
count += 1
except IOError:
print "Can't open myfile"
(I know, this is bad, I never close the file, but its just for
illustration). But then I change it to:
try:
for line in open(myFileName):
count += openAndProcessSubfile(lin
10 matches
Mail list logo