"Bryan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> if i really want to handle the exception, then i handle it at a
conceptually
> "higher" level by wrapping it in an exception which is basically what some
> higher-level routine would do anyways.
>
>
> try:
> f = open('file)
"Peter Hansen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> So this is better, though probably excessive in small scripts:
>
> try:
> f = open('file')
> except IOError:
> # do something else
> else:
> try:
> content = f.read()
> finally:
> f.
Peter Hansen wrote:
> 3c273 wrote:
>> "Robert Kern" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>
>>> Paul Rubin wrote:
>>>
Say that the open is inside the try block. If the file can't be
opened, then 'open' raises an exception, 'f' doesn't get set, and then
the
3c273 wrote:
> "Robert Kern" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>>Paul Rubin wrote:
>>
>>>Say that the open is inside the try block. If the file can't be
>>>opened, then 'open' raises an exception, 'f' doesn't get set, and then
>>>the 'finally' clause tries to close f
"Robert Kern" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Paul Rubin wrote:
> > Say that the open is inside the try block. If the file can't be
> > opened, then 'open' raises an exception, 'f' doesn't get set, and then
> > the 'finally' clause tries to close f. f might have been
Paul Rubin wrote:
> "3c273" <[EMAIL PROTECTED]> writes:
>
>>>f = open(file)
>>>try:
>>>contents = f.read()
>>>finally:
>>>f.close()
>>>
>>
>>Pardon the newbie question, but could you explain why? I have been doing it
>>the same way as the OP and would like to know the difference. Thank you
"3c273" <[EMAIL PROTECTED]> writes:
> > f = open(file)
> > try:
> > contents = f.read()
> > finally:
> > f.close()
> >
> Pardon the newbie question, but could you explain why? I have been doing it
> the same way as the OP and would like to know the difference. Thank you.
Say that the open
"Erik Max Francis" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Note quite. The assignment of the resources to its variable needs to be
> done before the try:
>
> f = open(file)
> try:
> contents = f.read()
> finally:
> f.close()
>
Pardon the newbie question, but could you
Sandra-24 wrote:
> I was reading over some python code recently, and I saw something like
> this:
>
> contents = open(file).read()
>
> And of course you can also do:
>
> open(file, "w").write(obj)
>
> Why do they no close the files? Is this sloppy programming or is the
> file automatically clos
Erik Max Francis wrote:
> Robert Kern wrote:
>
>>>I usually use:
>>>
>>>try:
>>> f = open(file)
>>> contents = f.read()
>>>finally:
>>> f.close()
>>>
>>>But now I am wondering if that is the same thing. Which method would
>>>you rather use? Why?
>>
>>Just keep doing what you are doing, please.
Robert Kern wrote:
>> I usually use:
>>
>> try:
>> f = open(file)
>> contents = f.read()
>> finally:
>> f.close()
>>
>> But now I am wondering if that is the same thing. Which method would
>> you rather use? Why?
>
> Just keep doing what you are doing, please.
Note quite. The assignment
Sandra-24 a écrit :
> I was reading over some python code recently, and I saw something like
> this:
>
> contents = open(file).read()
>
> And of course you can also do:
>
> open(file, "w").write(obj)
>
> Why do they no close the files? Is this sloppy programming or is the
> file automatically c
Marcin Mielżyński wrote:
> Sandra-24 wrote:
>> I was reading over some python code recently, and I saw something like
>> this:
>>
>> contents = open(file).read()
>>
>> And of course you can also do:
>>
>> open(file, "w").write(obj)
>>
>> Why do they no close the files? Is this sloppy programming or
Sandra-24 wrote:
> I was reading over some python code recently, and I saw something like
> this:
>
> contents = open(file).read()
>
> And of course you can also do:
>
> open(file, "w").write(obj)
>
> Why do they no close the files? Is this sloppy programming or is the
> file automatically clos
Sandra-24 wrote:
> I was reading over some python code recently, and I saw something like
> this:
>
> contents = open(file).read()
>
> And of course you can also do:
>
> open(file, "w").write(obj)
>
> Why do they no close the files? Is this sloppy programming or is the
> file automatically clos
I was reading over some python code recently, and I saw something like
this:
contents = open(file).read()
And of course you can also do:
open(file, "w").write(obj)
Why do they no close the files? Is this sloppy programming or is the
file automatically closed when the reference is destroyed (aft
16 matches
Mail list logo