473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

closing file

Hello,

Once I open a file, for example as:
class MyClass:
def logFileOpen( self ):
self.fdFilenameLog = file( self.filenameLog, 'a' )
return

I cannot find in hte documentation how to make sure the file are closed.

I guess that Python is closing all files at the end of the application
or when an Exception is raised

Is this true ?
Is the file closed when the destructor is called ? ( Internally because
I don't see a way to call a destructor in Python ).

Thank you very much,
Marcello
Jul 18 '05 #1
1 1167
In article <ma**************************************@python.o rg>,
Marcello Pietrobon <te*****@attglobal.net> wrote:
Once I open a file, for example as:
class MyClass:
def logFileOpen( self ):
self.fdFilenameLog = file( self.filenameLog, 'a' )
return

I cannot find in hte documentation how to make sure the file are closed.


File objects have a close() method that you can call. See
<http://docs.python.org/lib/bltin-file-objects.html>

-Mark
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
2
by: Atulvid | last post by:
Hi, I created a test file for my application by writing structures to a binary file. To make sure that I will get correct data for the pointers inside the structure, i wrote actual data they...
1
by: MuZZy | last post by:
HI, I have a user control, say with one textBox. I need the following: when the user closes form (either calling Form.Close, or pressing "X" or anyhow), UserControl copies a file from a...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
3
by: Carroll, Barry | last post by:
Greetings: Please forgive me if this is the wrong place for this post. I couldn't find a more acceptable forum. If there is one, please point me in the right direction. I am part of a small...
6
by: Steven D'Aprano | last post by:
Closing a file can (I believe) raise an exception. Is that documented anywhere? I've spent a lot of frustrating time trying to track this down, with no luck, which suggests that either my...
1
by: Paul Rubin | last post by:
it looks like contextlib.closing fails to be idempotent, i.e. wrapping closing() around another closing() doesn't work. This is annoying because the idea of closing() is to let you use legacy...
5
by: buu | last post by:
I have an app made in vb.net with a part of it made in vc.net. after finishing a data processing with a file, I would like to delete that file, but file remains locked to be sure, I was: -...
11
by: Simon van Beek | last post by:
Dear reader, By opening an application I get always the main Access window with the closing cross in the above right corner. Is there a possibility to make this closing cross invisible? ...
4
Fr33dan
by: Fr33dan | last post by:
Hi, I'm having trouble with a multi-threaded program crashing on a specific machine when the worker thread is not initialized at when the _FormClosing method of my main form called. Here is my...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.