Re: Semantics of file.close()

2007-07-18 Thread Hrvoje Niksic
"Evan Klitzke" <[EMAIL PROTECTED]> writes: >> But the writes are buffered, and close causes the buffer to be >> flushed. file.close can throw an exception just like fclose, but >> it will still ensure that the file is closed. > > Is this buffering being done by Python or the kernel? It is done i

Re: Semantics of file.close()

2007-07-17 Thread Paul Rubin
"Evan Klitzke" <[EMAIL PROTECTED]> writes: > Is this buffering being done by Python or the kernel? I think this refers to buffering done in the C stdio library, which Python uses. -- http://mail.python.org/mailman/listinfo/python-list

Re: Semantics of file.close()

2007-07-17 Thread Evan Klitzke
On 7/17/07, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > "Evan Klitzke" <[EMAIL PROTECTED]> writes: > > > You should take a look at the man pages for close(2) and write(2) (not > > fclose). Generally you will only get an error in C if you try to close > > a file that isn't open. In Python you don't e

Re: Semantics of file.close()

2007-07-17 Thread Matthew Woodcraft
Donn Cave <[EMAIL PROTECTED]> wrote: > I don't think there's any remedy for it, other than the obvious - > either always flush, or wrap an explicit close in its own exception > handler. Even if you have flushed, close() can give an error with some filesystems. -M- -- http://mail.python.org/mai

Re: Semantics of file.close()

2007-07-17 Thread Hrvoje Niksic
"Evan Klitzke" <[EMAIL PROTECTED]> writes: > You should take a look at the man pages for close(2) and write(2) (not > fclose). Generally you will only get an error in C if you try to close > a file that isn't open. In Python you don't even have to worry about > that -- if you close a regular file

Re: Semantics of file.close()

2007-07-17 Thread Donn Cave
In article <[EMAIL PROTECTED]>, "Evan Klitzke" <[EMAIL PROTECTED]> wrote: ... > > How do I ensure that the close() methods in my finally clause do not > > throw an exception? > You should take a look at the man pages for close(2) and write(2) (not > fclose). Generally you will only get an error

Re: Semantics of file.close()

2007-07-17 Thread Evan Klitzke
On 7/16/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > > I'm a Python beginner and I'm trying to open, write and close a file > in a > correct manner. I've RTFM, RTFS, and I've read this thread: > http://groups.google.ca/group/comp.lang.python/browse_thread/thread/73bbda2c920521c/98c73

Re: Semantics of file.close()

2007-07-16 Thread Matimus
> How do I ensure that the close() methods in my finally clause do not > throw an exception? You have no choice. If close is going to fail, it will fail. Fortunately you can catch the exception and continue on. try: try: file1.write(somestuff) finally: file1.close() except

Re: Semantics of file.close()

2007-07-16 Thread Dan Bishop
On Jul 16, 6:35 pm, [EMAIL PROTECTED] wrote: > Hello, > > I'm a Python beginner and I'm trying to open, write and close a file > in a > correct manner. I've RTFM, RTFS, and I've read this > thread:http://groups.google.ca/group/comp.lang.python/browse_thread/thread/7... > > I still cannot figure ou

Re: Semantics of file.close()

2007-07-16 Thread seerdecker
Sorry for the bad formatting; I've had to post this through the google groups. -- http://mail.python.org/mailman/listinfo/python-list

Semantics of file.close()

2007-07-16 Thread seerdecker
Hello, I'm a Python beginner and I'm trying to open, write and close a file in a correct manner. I've RTFM, RTFS, and I've read this thread: http://groups.google.ca/group/comp.lang.python/browse_thread/thread/73bbda2c920521c/98c731229d86b01d?lnk=st&q=python+file+explicit+close&rnum=1&hl=en#98c7312