Re: [Tutor] finally without try or except

2012-07-31 Thread Don Jennings
On Jul 31, 2012, at 12:26 PM, tutor-requ...@python.org wrote: > Message: 2 > Date: Tue, 31 Jul 2012 10:44:29 -0400 > From: Tino Dai > To: "Steven D'Aprano" > Cc: "tutor@python.org" > Subject: Re: [Tutor] finally without try or except > Message-ID

Re: [Tutor] finally without try or except

2012-07-31 Thread Hugo Arts
On Tue, Jul 31, 2012 at 5:23 PM, Prasad, Ramit wrote: > [snip] > > > >> This will be the most robust as it will > > >> also work for cases where the program is terminated without the use of > > >> the keyboard (i.e. kill -9, task manager, computer reboot, etc.) but > > > > That unfortunately is n

Re: [Tutor] finally without try or except

2012-07-31 Thread Prasad, Ramit
[snip] > >> This will be the most robust as it will > >> also work for cases where the program is terminated without the use of > >> the keyboard (i.e. kill -9, task manager, computer reboot, etc.) but > > That unfortunately is not so. kill -9 does *not* send a signal or raise an > exception. It

Re: [Tutor] finally without try or except

2012-07-31 Thread Tino Dai
On Mon, Jul 30, 2012 at 9:01 PM, Steven D'Aprano wrote: > If you want to be robust, it is best not to try to beat the database. That > means you should write to the database as soon as you can, as often as you > need to, and let the database do what it does best: reliable transaction > storage. An

Re: [Tutor] finally without try or except

2012-07-30 Thread Steven D'Aprano
Tino Dai wrote: I just remember that there was a performance hit or something for doing that. Does that sound familiar to anyone? Yes, and no. Creating a try block in Python is lightweight and fast. It is about as fast as the "pass" statement, that is, pretty damn fast and more or less faste

Re: [Tutor] finally without try or except

2012-07-30 Thread Steven D'Aprano
Tino Dai wrote: Yes, but that would involve surrounding the entire method with a try except finally block. I was told by the Python-Guru-In Residence that shouldn't emulate Java code in Python, and that was generally bad programming practice (no flame war intended) And that is correct. It is *

Re: [Tutor] finally without try or except

2012-07-30 Thread eryksun
On Mon, Jul 30, 2012 at 3:10 PM, Tino Dai wrote: > On Mon, Jul 30, 2012 at 1:52 PM, Mark Lawrence > wrote: > >> Sorry I'm not completely sure what you're asking for but will this help >> http://docs.python.org/library/atexit.html ? >> > I think this might be what I'm looking for. But for about 2

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 3:35 PM, Brett Ritter wrote: > On Mon, Jul 30, 2012 at 12:20 PM, Tino Dai wrote: > > Yes, but that would involve surrounding the entire method with a try > except > > finally block. I was > > told by the Python-Guru-In Residence that shouldn't emulate Java code in > > Pyt

Re: [Tutor] finally without try or except

2012-07-30 Thread Brett Ritter
On Mon, Jul 30, 2012 at 12:20 PM, Tino Dai wrote: > Yes, but that would involve surrounding the entire method with a try except > finally block. I was > told by the Python-Guru-In Residence that shouldn't emulate Java code in > Python, and that was > generally bad programming practice (no flame wa

Re: [Tutor] finally without try or except

2012-07-30 Thread Steve Willoughby
On 30-Jul-12 10:52, Mark Lawrence wrote: On 30/07/2012 17:56, Tino Dai wrote: Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? Sorry I'm not completely sure what you're askin

Re: [Tutor] finally without try or except

2012-07-30 Thread Alan Gauld
On 30/07/12 17:56, Tino Dai wrote: Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? Yes, try/finally. That's what it's there for. I was thinking about maybe a free standing

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 1:44 PM, Prasad, Ramit wrote: > > Actually, what I'm doing is keeping a pending item log in memory as an > array > > and then saving it to the DB at the end of the program, but what happens > if > > the user hits ctrl-c, then the pending items array is lost. That's the > us

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 2:44 PM, Albert-Jan Roskam wrote: > *From:* Tino Dai > > *To:* nz*tutor pythonzzz > *Sent:* Monday, July 30, 2012 6:56 PM > *Subject:* [Tutor] finally without try or except > > Hi! > > Is there anyway to execute a block of code at th

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 1:52 PM, Mark Lawrence wrote: > On 30/07/2012 17:56, Tino Dai wrote: > >> Hi! >> >> Is there anyway to execute a block of code at the end of a program >> in >> 2.6 regardless of what happened before eg exiting normally or died because >> of an exception? >> I was thin

Re: [Tutor] finally without try or except

2012-07-30 Thread Albert-Jan Roskam
From: Tino Dai To: nz*tutor pythonzzz >Sent: Monday, July 30, 2012 6:56 PM >Subject: [Tutor] finally without try or except > > >Hi! > > >     Is there anyway to execute a block of code at the end of a program in 2.6 >regardless of what happened before eg exiting

Re: [Tutor] finally without try or except

2012-07-30 Thread Mark Lawrence
On 30/07/2012 17:56, Tino Dai wrote: Hi! Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? I was thinking about maybe a free standing finally code block or a decorator. Any hint

Re: [Tutor] finally without try or except

2012-07-30 Thread Prasad, Ramit
> Actually, what I'm doing is keeping a pending item log in memory as an array > and then saving it to the DB at the end of the program, but what happens if > the user hits ctrl-c, then the pending items array is lost. That's the use > case that I'm looking for a solution to. http://docs.python.or

Re: [Tutor] finally without try or except

2012-07-30 Thread Tino Dai
On Mon, Jul 30, 2012 at 1:16 PM, Marc Tompkins wrote: > On Mon, Jul 30, 2012 at 9:56 AM, Tino Dai wrote: > >> Hi! >> >> Is there anyway to execute a block of code at the end of a program >> in 2.6 regardless of what happened before eg exiting normally or died >> because of an exception? >> I

Re: [Tutor] finally without try or except

2012-07-30 Thread Marc Tompkins
On Mon, Jul 30, 2012 at 9:56 AM, Tino Dai wrote: > Hi! > > Is there anyway to execute a block of code at the end of a program in > 2.6 regardless of what happened before eg exiting normally or died because > of an exception? > I was thinking about maybe a free standing finally code block or

[Tutor] finally without try or except

2012-07-30 Thread Tino Dai
Hi! Is there anyway to execute a block of code at the end of a program in 2.6 regardless of what happened before eg exiting normally or died because of an exception? I was thinking about maybe a free standing finally code block or a decorator. Any hints? Tino

Re: [Tutor] Finally finished my currency exchange program

2010-12-03 Thread Eddie
Its Windows only as that is what I am more comfortable with and I don't use Linux (tried and not had much luck with it really). Yes, the installer is Windows only. Also, No, I didn't just register on thsi list, I've been registered on this list for years. Dink On 4 December 2010 01:54, Evans Any

Re: [Tutor] Finally finished my currency exchange program

2010-12-03 Thread Evans Anyokwu
I didn't find any of his previous questions as well - Looks like he just registered on this list to try and promote his product. Sneaky! On Fri, Dec 3, 2010 at 2:21 PM, Joel Goldstick wrote: > > On Fri, Dec 3, 2010 at 8:07 AM, Alan Gauld wrote: > >> >> "Eddie" wrote in message >> news:aanlktim

Re: [Tutor] Finally finished my currency exchange program

2010-12-03 Thread Joel Goldstick
On Fri, Dec 3, 2010 at 8:07 AM, Alan Gauld wrote: > > "Eddie" wrote in message > news:aanlktimxrajnbvj9egx4diqbwrb1ltfa9quv2fdeq...@mail.gmail.com... > > I've finally finished my currency exchange program thanks to help from >> this >> list and another list. It updates the exchange rates via an

Re: [Tutor] Finally finished my currency exchange program

2010-12-03 Thread Alan Gauld
"Eddie" wrote in message news:aanlktimxrajnbvj9egx4diqbwrb1ltfa9quv2fdeq...@mail.gmail.com... I've finally finished my currency exchange program thanks to help from this list and another list. It updates the exchange rates via an xml feed etc. If you wrote it in Python why only Windows sup

Re: [Tutor] Finally finished my currency exchange program

2010-12-03 Thread danielle davout
sadly you didn't take into account Linux users On 12/3/10, Eddie wrote: > I've finally finished my currency exchange program thanks to help from this > list and another list. It updates the exchange rates via an xml feed etc. > > Feedback on it would be appreciated please: > http://www.dinksoftw

[Tutor] Finally finished my currency exchange program

2010-12-03 Thread Eddie
I've finally finished my currency exchange program thanks to help from this list and another list. It updates the exchange rates via an xml feed etc. Feedback on it would be appreciated please: http://www.dinksoftware.com/astute_currency_analyzer.php Dink

Re: [Tutor] finally

2010-06-26 Thread Christopher King
sorry, my reply to all button goofed up On Sat, Jun 26, 2010 at 7:43 PM, Steven D'Aprano wrote: > Hi Christopher, > > Are you aware you have written directly to me instead of the tutor > mailing list? It's normally considered rude to do so, unless your > message truly is meant to be private. > >

Re: [Tutor] finally

2010-06-24 Thread Steven D'Aprano
On Fri, 25 Jun 2010 12:29:12 am Walter Prins wrote: > On 24 June 2010 15:08, Christopher King wrote: > > so if you encounter an error that you won't handle, but you still > > to close files and save data, you could use finally? > > More strongly, you *should* use finally, as there's no other way t

Re: [Tutor] finally

2010-06-24 Thread Steven D'Aprano
On Thu, 24 Jun 2010 11:06:24 pm Hugo Arts wrote: > If you need to do some cleanup, putting it in a finally block is the > only way to *guarantee* it will run. To be pedantic, the finally clause will always run, *provided* the code in the try block itself exits (either by finishing or by raising

Re: [Tutor] finally

2010-06-24 Thread Chris
On 06/24/2010 10:44 AM, Walter Prins wrote: On 24 June 2010 15:34, Chris http://g.nius.ck>@gmail.com > wrote: cleanup code means code to close files and save data, right Possibly yes, although I'm referring generally to freeing any resources (objects, memory, files, wha

Re: [Tutor] finally

2010-06-24 Thread Chris
On 06/23/2010 10:59 PM, bob gailer wrote: On 6/23/2010 7:36 PM, Christopher King wrote: In a try except clause, you can end with finally block. I know it runs after the try and except blocks regardless of the outcome, but why use it. Couldn't you just put the code after the try and except

Re: [Tutor] finally

2010-06-24 Thread Walter Prins
On 24 June 2010 15:34, Chris wrote: > cleanup code means code to close files and save data, right > Possibly yes, although I'm referring generally to freeing any resources (objects, memory, files, whatever) your code has acquired/opened that should be freed whether or not the code succeeds (with

Re: [Tutor] finally

2010-06-24 Thread Chris
On 06/24/2010 10:29 AM, Walter Prins wrote: On 24 June 2010 15:08, Christopher King @gmail.com > wrote: so if you encounter an error that you won't handle, but you still to close files and save data, you could use finally? More strongly, you *should*

Re: [Tutor] finally

2010-06-24 Thread Walter Prins
On 24 June 2010 15:08, Christopher King wrote: > so if you encounter an error that you won't handle, but you still to close > files and save data, you could use finally? > More strongly, you *should* use finally, as there's no other way to ensure your cleanup code will run regardless of unpredic

Re: [Tutor] finally

2010-06-24 Thread Christopher King
so if you encounter an error that you won't handle, but you still to close files and save data, you could use finally? On Thu, Jun 24, 2010 at 10:05 AM, Christopher King wrote: > let me try it > > On Thu, Jun 24, 2010 at 9:38 AM, Hugo Arts wrote: > >> On Thu, Jun 24, 2010 at 3:13 PM, Christopher

Re: [Tutor] finally

2010-06-24 Thread Hugo Arts
On Thu, Jun 24, 2010 at 3:13 PM, Christopher King wrote: > i mean isn't handled > When I said "guaranteed to run," I meant it. finally will *always* run after your try clause, exceptions or not, handled or not. And by manual, he means the python reference manual. He was quoting a part covering th

Re: [Tutor] finally

2010-06-24 Thread Christopher King
what manual? On Wed, Jun 23, 2010 at 10:59 PM, bob gailer wrote: > On 6/23/2010 7:36 PM, Christopher King wrote: > > In a try except clause, you can end with finally block. I know it runs > after the try and except blocks regardless of the outcome, but why use it. > Couldn't you just put th

Re: [Tutor] finally

2010-06-24 Thread Christopher King
i mean isn't handled On Thu, Jun 24, 2010 at 9:12 AM, Christopher King wrote: > you mean it will always run even if the exception is handled? > > > On Thu, Jun 24, 2010 at 9:06 AM, Hugo Arts wrote: > >> On Thu, Jun 24, 2010 at 4:36 AM, Christopher King >> wrote: >> > In a try except clause,

Re: [Tutor] finally

2010-06-24 Thread Christopher King
you mean it will always run even if the exception is handled? On Thu, Jun 24, 2010 at 9:06 AM, Hugo Arts wrote: > On Thu, Jun 24, 2010 at 4:36 AM, Christopher King > wrote: > > In a try except clause, you can end with finally block. I know it > runs > > after the try and except blocks regar

Re: [Tutor] finally

2010-06-24 Thread Hugo Arts
On Thu, Jun 24, 2010 at 4:36 AM, Christopher King wrote: >     In a try except clause, you can end with finally block. I know it runs > after the try and except blocks regardless of the outcome, but why use it. > Couldn't you just put the code after the try and except block without using > a final

Re: [Tutor] finally

2010-06-23 Thread bob gailer
On 6/23/2010 7:36 PM, Christopher King wrote: In a try except clause, you can end with finally block. I know it runs after the try and except blocks regardless of the outcome, but why use it. Couldn't you just put the code after the try and except block without using a finally block. Does t

[Tutor] finally

2010-06-23 Thread Christopher King
In a try except clause, you can end with finally block. I know it runs after the try and except blocks regardless of the outcome, but why use it. Couldn't you just put the code after the try and except block without using a finally block. Does the finally command do something I don't know about