File Handling & TRY/EXCEPT
Alex Popescu
nospam.themindstorm at gmail.com
Fri Aug 3 14:45:14 EDT 2007
"Robert Rawlins - Think Blue" <robert.rawlins at thinkbluemedia.co.uk>
wrote in news:13677.732498809$1186148538 at news.gmane.org:
> Thanks for your ideas guys,
>
> I'm unfortunately tied to 2.4 so don't have the full try except
> status, but I'm now working with the following code:
>
> def addApp(self, event):
> try:
> logfile =
> open('/pblue/new/Logs/Application.csv','a')
>
> now = datetime.datetime.now()
> logstring = '%s,%s \n' % (event, str(now))
>
> try:
> logfile.write(logstring)
> finally:
> logfile.close()
> except:
> self.addApp(event)
>
> I'm trying to slowly debug my app and get rid of all the memory leaks,
> but its pain staking work, any help you can offer on that stuff would
> be a god send, I'm a little reluctant about posting all my app code on
> the lists as I'd like to keep some of it private.
>
> How does that new version look? A little tidier?
>
> Thanks guys,
>
Now, you are sure the file is always close. What I don't think is
correct is to retry to re-write the event (cause if opening the file
crashed ones there are very good chances that it will throw the 2nd
time).
./alex
--
.w( the_mindstorm )p.
More information about the Python-list
mailing list