[issue45890] Add tests for tracing try-except-finally blocks

2021-12-07 Thread Irit Katriel
Change by Irit Katriel : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue45890] Add tests for tracing try-except-finally blocks

2021-12-07 Thread Mark Shannon
New submission from Mark Shannon : New changeset a310fd83a014484b8c680de83540c4908b344c6c by Irit Katriel in branch 'main': bpo-45890: Add tests for tracing try-except-finally blocks (GH-29746) https://github.com/python/cpython/commit/a310fd83a014484b8c680de83540c4908b344c6c -- nosy

[issue45890] Add tests for tracing try-except-finally blocks

2021-11-24 Thread Irit Katriel
Change by Irit Katriel : -- keywords: +patch pull_requests: +27983 stage: -> patch review pull_request: https://github.com/python/cpython/pull/29746 ___ Python tracker ___

[issue45890] Add tests for tracing try-except-finally blocks

2021-11-24 Thread Irit Katriel
Change by Irit Katriel : -- assignee: iritkatriel components: Interpreter Core, Tests nosy: iritkatriel priority: normal severity: normal status: open title: Add tests for tracing try-except-finally blocks type: enhancement versions: Python 3.11

[issue43458] Tutorial should mention about variable scope in try/except/finally

2021-03-12 Thread Éric Araujo
Éric Araujo added the comment: The only blocks that create scopes are modules, class and functions. if, try, with, for, while, etc are blocks but not new scopes. For the tutorial it could be nice to have an explicit mention and example of this. -- nosy: +eric.araujo

[issue43458] Tutorial should mention about variable scope in try/except/finally

2021-03-09 Thread Marek M
components: Documentation messages: 388407 nosy: deekox, docs@python priority: normal severity: normal status: open title: Tutorial should mention about variable scope in try/except/finally type: enhancement versions: Python 3.9 ___ Python tracker <ht

[issue42634] Incorrect line number in bytecode for try-except-finally

2021-02-01 Thread Mark Shannon
Mark Shannon added the comment: Sorry. I forgot the close the issue when it was fixed. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue42634] Incorrect line number in bytecode for try-except-finally

2021-02-01 Thread Ned Batchelder
Ned Batchelder added the comment: This problem no longer appears with master (commit 9eb11a139f). -- ___ Python tracker ___ ___

[issue42634] Incorrect line number in bytecode for try-except-finally

2021-02-01 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: Friendly reminder that this issue is currently blocking the 3.10a5 release. If you are ok with waiting for the next release to include the fix, please say so here or drop me an email/ -- nosy: +pablogsal

[issue42634] Incorrect line number in bytecode for try-except-finally

2020-12-21 Thread Mark Shannon
Mark Shannon added the comment: New changeset f2dbfd7e20431f0bcf2b655aa876afec7fe03c6f by Mark Shannon in branch 'master': bpo-42634: Mark reraise after except blocks as artificial. (GH-23877) https://github.com/python/cpython/commit/f2dbfd7e20431f0bcf2b655aa876afec7fe03c6f --

[issue42634] Incorrect line number in bytecode for try-except-finally

2020-12-21 Thread Mark Shannon
Change by Mark Shannon : -- pull_requests: +22740 stage: resolved -> patch review pull_request: https://github.com/python/cpython/pull/23877 ___ Python tracker ___

[issue42634] Incorrect line number in bytecode for try-except-finally

2020-12-21 Thread Mark Shannon
Change by Mark Shannon : -- resolution: fixed -> ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue42634] Incorrect line number in bytecode for try-except-finally

2020-12-20 Thread Ned Batchelder
Ned Batchelder added the comment: (Rather: line 8 isn't executed, and so should not be traced.) -- ___ Python tracker ___ ___

[issue42634] Incorrect line number in bytecode for try-except-finally

2020-12-20 Thread Ned Batchelder
Ned Batchelder added the comment: I checked on this with CPython commit c95f8bc270. The code above is fixed, but this code has a similar problem: a, b, c = 1, 1, 1 try: try: a = 4/0 # ZeroDivisionError except ValueError: b = 6 except IndexError: a

[issue42634] Incorrect line number in bytecode for try-except-finally

2020-12-14 Thread Mark Shannon
Change by Mark Shannon : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue42634] Incorrect line number in bytecode for try-except-finally

2020-12-14 Thread Mark Shannon
Change by Mark Shannon : -- keywords: +patch pull_requests: +22616 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/23760 ___ Python tracker

[issue42634] Incorrect line number in bytecode for try-except-finally

2020-12-13 Thread Mark Shannon
/6c5dedde9df8d2de13de8a6a39a5f112 -- assignee: Mark.Shannon messages: 382958 nosy: Mark.Shannon, nedbat priority: release blocker severity: normal stage: needs patch status: open title: Incorrect line number in bytecode for try-except-finally type: behavior versions: Python 3.10

Re: try/except/finally

2014-06-11 Thread alister
On Wed, 11 Jun 2014 00:00:49 +, Steven D'Aprano wrote: On Wed, 11 Jun 2014 06:37:01 +1000, Chris Angelico wrote: I don't know a single piece of programming advice which, if taken as an inviolate rule, doesn't at some point cause suboptimal code. Don't try to program while your cat is

Re: try/except/finally

2014-06-11 Thread Roy Smith
In article NxUlv.352165$uI3.258913@fx18.am4, alister alister.nospam.w...@ntlworld.com wrote: On Wed, 11 Jun 2014 00:00:49 +, Steven D'Aprano wrote: On Wed, 11 Jun 2014 06:37:01 +1000, Chris Angelico wrote: I don't know a single piece of programming advice which, if taken as an

Re: try/except/finally

2014-06-10 Thread Thomas Rachel
Am 08.06.2014 05:58 schrieb Rustom Mody: Some people¹ think that gotos are a code-smell. ¹ I am not exactly those people. A chap called E W Dijkstra made the statement: Goto statement considered harmful and became famous. And became widely misunderstood. If anybody would read the whole what

Re: try/except/finally

2014-06-10 Thread Marko Rauhamaa
Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@spamschutz.glglgl.de: Essentially, you can write both good and bad code both with and without goto. Point is, choose tasteful idioms in your code. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: try/except/finally

2014-06-10 Thread Rustom Mody
On Tuesday, June 10, 2014 12:57:29 PM UTC+5:30, Thomas Rachel wrote: Am 08.06.2014 05:58 schrieb Rustom Mody: Some people� think that gotos are a code-smell. � I am not exactly those people. A chap called E W Dijkstra made the statement: Goto statement considered harmful and became

Re: try/except/finally

2014-06-10 Thread Skip Montanaro
Here is Dijkstra: http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html ... And here is Hoare... | Ada has a plethora of features and notational conventions, many of them | unnecessary and some of them, like exception handling, even | dangerous. Do not allow

Re: try/except/finally

2014-06-10 Thread Mark Lawrence
On 10/06/2014 08:27, Thomas Rachel wrote: Am 08.06.2014 05:58 schrieb Rustom Mody: Some people¹ think that gotos are a code-smell. ¹ I am not exactly those people. A chap called E W Dijkstra made the statement: Goto statement considered harmful and became famous. And became widely

Re: try/except/finally

2014-06-10 Thread Grant Edwards
On 2014-06-10, Mark Lawrence breamore...@yahoo.co.uk wrote: I entirely agree. I find it incredible that some people find it so difficult to differentiate having tens or even hundreds of gotos leaping around willy nilly to a similar number of labels, and a similar number of gotos targetted

Re: try/except/finally

2014-06-10 Thread alister
On Tue, 10 Jun 2014 19:14:18 +0100, Mark Lawrence wrote: On 10/06/2014 08:27, Thomas Rachel wrote: Am 08.06.2014 05:58 schrieb Rustom Mody: Some people¹ think that gotos are a code-smell. ¹ I am not exactly those people. A chap called E W Dijkstra made the statement: Goto statement

Re: try/except/finally

2014-06-10 Thread Chris Angelico
On Wed, Jun 11, 2014 at 4:48 AM, Grant Edwards invalid@invalid.invalid wrote: I've seen some amazingly convoluted C code where people got themselves wrapped around the axle six different ways in order to avoid using goto fail or goto retry. Invariably I was looking at the code because it

Re: try/except/finally

2014-06-10 Thread Roy Smith
In article mailman.10972.1402432630.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: Yeah. As soon as you take on board a hard-and-fast rule, you open yourself up to stupid cases where the rule ought to have been broken. I don't know a single piece of programming advice

Re: try/except/finally

2014-06-10 Thread Chris Angelico
On Wed, Jun 11, 2014 at 6:38 AM, Roy Smith r...@panix.com wrote: In article mailman.10972.1402432630.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: Yeah. As soon as you take on board a hard-and-fast rule, you open yourself up to stupid cases where the rule ought to have

Re: try/except/finally

2014-06-10 Thread Ethan Furman
On 06/10/2014 01:38 PM, Roy Smith wrote: Chris Angelico wrote: # Yeah. As soon as you take on board a hard-and-fast rule, you open yourself up to stupid cases where the rule ought to have been broken. I don't know a single piece of programming advice which, if taken as an inviolate rule,

Re: try/except/finally

2014-06-10 Thread Mark Lawrence
On 10/06/2014 21:43, Ethan Furman wrote: On 06/10/2014 01:38 PM, Roy Smith wrote: Chris Angelico wrote: # Yeah. As soon as you take on board a hard-and-fast rule, you open yourself up to stupid cases where the rule ought to have been broken. I don't know a single piece of programming advice

Re: try/except/finally

2014-06-10 Thread Steven D'Aprano
On Wed, 11 Jun 2014 06:37:01 +1000, Chris Angelico wrote: I don't know a single piece of programming advice which, if taken as an inviolate rule, doesn't at some point cause suboptimal code. Don't try to program while your cat is sleeping on the keyboard. -- Steven D'Aprano

Re: try/except/finally

2014-06-10 Thread Chris Angelico
On Wed, Jun 11, 2014 at 10:00 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 11 Jun 2014 06:37:01 +1000, Chris Angelico wrote: I don't know a single piece of programming advice which, if taken as an inviolate rule, doesn't at some point cause suboptimal code. Don't

Re: try/except/finally

2014-06-10 Thread Roy Smith
On Wed, Jun 11, 2014 at 10:00 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Don't try to program while your cat is sleeping on the keyboard. In article mailman.10989.1402445543.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: Hmm. I've never actually

Re: try/except/finally

2014-06-10 Thread Tim Delaney
On 11 June 2014 10:00, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 11 Jun 2014 06:37:01 +1000, Chris Angelico wrote: I don't know a single piece of programming advice which, if taken as an inviolate rule, doesn't at some point cause suboptimal code. Don't try to

Re: try/except/finally

2014-06-10 Thread Mark Lawrence
On 11/06/2014 01:40, Tim Delaney wrote: On 11 June 2014 10:00, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info mailto:steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 11 Jun 2014 06:37:01 +1000, Chris Angelico wrote: I don't know a single piece of programming advice

Re: try/except/finally

2014-06-10 Thread Chris Angelico
On Wed, Jun 11, 2014 at 10:53 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: Does it make any difference if the cat is European or African? What? I don't know. ARGH! ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: try/except/finally

2014-06-10 Thread Mark Lawrence
On 11/06/2014 02:00, Chris Angelico wrote: On Wed, Jun 11, 2014 at 10:53 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: Does it make any difference if the cat is European or African? What? I don't know. ARGH! ChrisA Awfully sorry, it's 2 a.m. here, next

Re: try/except/finally

2014-06-10 Thread Rustom Mody
On Tuesday, June 10, 2014 11:41:45 PM UTC+5:30, Skip Montanaro wrote: Would be interesting to get their collective take on C++... Are there any good parts? It appears the book was cancelled

Re: try/except/finally

2014-06-09 Thread Philip Shaw
On 2014-06-08, Dave Angel da...@davea.name wrote: Frank B fbick...@gmail.com Wrote in message: Ok; this is a bit esoteric. So finally is executed regardless of whether an exception occurs, so states the docs. But, I thought, if I return from my function first, that should take

Re: try/except/finally

2014-06-09 Thread Marko Rauhamaa
Philip Shaw jnufcvy...@tznvy.pbz: OTOH, it could just be that Guido didn't think of banning [return from finally] when exceptions were first added and doesn't want to introduce an incompatability later. You don't have to ban all nonsensical things. Most guns allow you to shoot yourself in the

Re: try/except/finally

2014-06-09 Thread Shiyao Ma
It would be great if someone could discuss it from the viewpoint of bytecode. e.g., how the stack is popped, etc. 2014-06-09 17:40 GMT+08:00 Marko Rauhamaa ma...@pacujo.net: Philip Shaw jnufcvy...@tznvy.pbz: OTOH, it could just be that Guido didn't think of banning [return from finally]

Re: try/except/finally

2014-06-09 Thread Skip Montanaro
On Mon, Jun 9, 2014 at 11:23 AM, Shiyao Ma i...@introo.me wrote: It would be great if someone could discuss it from the viewpoint of bytecode. e.g., how the stack is popped, etc. BITD, you couldn't have try/except/finally. You could have try/except or try/finally. You could nest the two

Re: try/except/finally

2014-06-08 Thread Marko Rauhamaa
Mark Lawrence breamore...@yahoo.co.uk: A return statement inside a finally block is code smell. Not to my nose. It seems like a perfectly reasonable thing to do. I agree, the code smell is the return in the except block. Here's a regular pattern that I use for nonblocking I/O: def

Re: try/except/finally

2014-06-08 Thread Joshua Landau
On 8 June 2014 08:12, Marko Rauhamaa ma...@pacujo.net wrote: Does anyone have an example motivating a return from finally? It seems to me it would always be a bad idea as it silently clears all unexpected exceptions. In a general sense: try: something_that_can_break()

Re: try/except/finally

2014-06-08 Thread Joshua Landau
On 6 June 2014 18:39, Roy Smith r...@panix.com wrote: The only way I can think of to bypass a finally block would be to call os._exit(), or send yourself a kill signal. If you're willing to use implementation details... --- # BreakN.py import sys # Turn tracing on if it is off if

Re: try/except/finally

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 12:02 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Jun 8, 2014 at 11:57 AM, Joshua Landau jos...@landau.ws wrote: On 8 June 2014 08:12, Marko Rauhamaa ma...@pacujo.net wrote: Does anyone have an example motivating a return from finally? It seems to me it would

Re: try/except/finally

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 11:57 AM, Joshua Landau jos...@landau.ws wrote: On 8 June 2014 08:12, Marko Rauhamaa ma...@pacujo.net wrote: Does anyone have an example motivating a return from finally? It seems to me it would always be a bad idea as it silently clears all unexpected exceptions. In

Re: try/except/finally

2014-06-07 Thread Ethan Furman
On 06/06/2014 11:22 AM, Ned Batchelder wrote: On 6/6/14 1:47 PM, Frank B wrote: Ok; thanks for the underscore and clarification. Just need to adjust my thinking a bit. Did this come up in real code? I've seen this point about finally/return semantics a number of times, but haven't seen

Re: try/except/finally

2014-06-07 Thread Chris Angelico
On Sun, Jun 8, 2014 at 8:49 AM, Ethan Furman et...@stoneleaf.us wrote: I don't remember if I almost had this in real code or if I learned about it first, but it can definitely be a gotcha. It seems to me that if the try block exits with an explicit return, and then the finally block exits with

Re: try/except/finally

2014-06-07 Thread Roy Smith
In article mailman.10867.1402184850.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: A return statement inside a finally block is code smell. Not to my nose. It seems like a perfectly reasonable thing to do. -- https://mail.python.org/mailman/listinfo/python-list

Re: try/except/finally

2014-06-07 Thread Mark Lawrence
On 08/06/2014 01:12, Roy Smith wrote: In article mailman.10867.1402184850.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: A return statement inside a finally block is code smell. Not to my nose. It seems like a perfectly reasonable thing to do. I agree, the code

Re: try/except/finally

2014-06-07 Thread Roy Smith
In article mailman.10871.1402189805.18130.python-l...@python.org, Mark Lawrence breamore...@yahoo.co.uk wrote: On 08/06/2014 01:12, Roy Smith wrote: In article mailman.10867.1402184850.18130.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: A return statement inside a

Re: try/except/finally

2014-06-07 Thread Rustom Mody
On Sunday, June 8, 2014 5:17:21 AM UTC+5:30, Chris Angelico wrote: On Sun, Jun 8, 2014 at 8:49 AM, Ethan Furman wrote: I don't remember if I almost had this in real code or if I learned about it first, but it can definitely be a gotcha. It seems to me that if the try block exits with an

try/except/finally

2014-06-06 Thread Frank B
Ok; this is a bit esoteric. So finally is executed regardless of whether an exception occurs, so states the docs. But, I thought, if I return from my function first, that should take precedence. au contraire Turns out that if you do this: try: failingthing() except FailException: return

Re: try/except/finally

2014-06-06 Thread Roy Smith
In article 0a89c96d-de62-42ad-be48-6107ce10d...@googlegroups.com, Frank B fbick...@gmail.com wrote: Ok; this is a bit esoteric. So finally is executed regardless of whether an exception occurs, so states the docs. But, I thought, if I return from my function first, that should take

Re: try/except/finally

2014-06-06 Thread Frank B
Ok; thanks for the underscore and clarification. Just need to adjust my thinking a bit. -- https://mail.python.org/mailman/listinfo/python-list

Re: try/except/finally

2014-06-06 Thread Ned Batchelder
On 6/6/14 1:47 PM, Frank B wrote: Ok; thanks for the underscore and clarification. Just need to adjust my thinking a bit. Did this come up in real code? I've seen this point about finally/return semantics a number of times, but haven't seen real code that needed adjusting based on it.

Re: Try-except-finally paradox

2014-01-31 Thread Göktuğ Kayaalp
Terry Reedy tjre...@udel.edu writes: I do not have any information on the topic, but I *imagine* that the when RETURN_VALUE opcode is evaluated within the context of an except block, it triggers a check for whether a corresponding finally block exists and should it exist, it is triggered, much

Re: Try-except-finally paradox

2014-01-30 Thread Chris Angelico
On Thu, Jan 30, 2014 at 11:05 PM, Dave Angel da...@davea.name wrote: The finally has to happen before any return inside the try or the except. And once you're in the finally clause you'll finish it before resuming the except clause. Since it has a return, that will happen before the

Re: Try-except-finally paradox

2014-01-30 Thread MRAB
On 2014-01-30 13:02, Chris Angelico wrote: On Thu, Jan 30, 2014 at 11:05 PM, Dave Angel da...@davea.name wrote: The finally has to happen before any return inside the try or the except. And once you're in the finally clause you'll finish it before resuming the except clause. Since it has a

Re: Try-except-finally paradox

2014-01-30 Thread Chris Angelico
On Fri, Jan 31, 2014 at 12:11 AM, MRAB pyt...@mrabarnett.plus.com wrote: One of the reasons that the 'with' statement was added was to prevent the mistake that you've just done. ;-) What if the file can't be opened? Yeah, whoops. The open shouldn't be inside try/finally. def func():

Re: Try-except-finally paradox

2014-01-30 Thread Rotwang
On 30/01/2014 06:33, Andrew Berg wrote: On 2014.01.29 23:56, Jessica Ross wrote: I found something like this in a StackOverflow discussion. def paradox(): ... try: ... raise Exception(Exception raised during try) ... except: ... print Except after try ...

Re: Try-except-finally paradox

2014-01-30 Thread Ethan Furman
On 01/30/2014 10:12 AM, Rotwang wrote: On 30/01/2014 06:33, Andrew Berg wrote: On 2014.01.29 23:56, Jessica Ross wrote: I found something like this in a StackOverflow discussion. -- def paradox(): ... try: ... raise Exception(Exception raised during try) ... except: ...

Re: Try-except-finally paradox

2014-01-30 Thread Terry Reedy
On 1/30/2014 7:05 AM, Dave Angel wrote: Jessica Ross deathwea...@gmail.com Wrote in message: I found something like this in a StackOverflow discussion. def paradox(): ... try: ... raise Exception(Exception raised during try) ... except: ... print Except after

Try-except-finally paradox

2014-01-29 Thread Jessica Ross
I found something like this in a StackOverflow discussion. def paradox(): ... try: ... raise Exception(Exception raised during try) ... except: ... print Except after try ... return True ... finally: ... print Finally ...

Re: Try-except-finally paradox

2014-01-29 Thread Ian Kelly
On Jan 29, 2014 11:01 PM, Jessica Ross deathwea...@gmail.com wrote: I found something like this in a StackOverflow discussion. def paradox(): ... try: ... raise Exception(Exception raised during try) ... except: ... print Except after try ...

Re: Try-except-finally paradox

2014-01-29 Thread Andrew Berg
On 2014.01.29 23:56, Jessica Ross wrote: I found something like this in a StackOverflow discussion. def paradox(): ... try: ... raise Exception(Exception raised during try) ... except: ... print Except after try ... return True ... finally:

Re: Try-except-finally paradox

2014-01-29 Thread wxjmfauth
Le jeudi 30 janvier 2014 06:56:16 UTC+1, Jessica Ross a écrit : I found something like this in a StackOverflow discussion. def paradox(): ... try: ... raise Exception(Exception raised during try) ... except: ... print Except after try ...

[issue1757118] utilize 2.5 try/except/finally in contextlib

2012-06-19 Thread Georg Brandl
Changes by Georg Brandl ge...@python.org: Removed file: http://bugs.python.org/file25625/1.html ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1757118 ___

[issue1757118] utilize 2.5 try/except/finally in contextlib

2012-05-17 Thread Fyrn Jilot
Changes by Fyrn Jilot fyrn7...@yahoo.com: Added file: http://bugs.python.org/file25625/1.html ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1757118 ___

[issue4529] parser module failure on valid try/except/finally blocks

2008-12-05 Thread Georg Brandl
Georg Brandl [EMAIL PROTECTED] added the comment: Fixed in r67576, will be ported to all branches. -- nosy: +georg.brandl resolution: - fixed status: open - closed ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4529

[issue4529] parser module failure on valid try/except/finally blocks

2008-12-04 Thread Kai Willadsen
New submission from Kai Willadsen [EMAIL PROTECTED]: Using the parser module to create a parse tree succeeds, but a subsequent tuple2ast fails, when parsing valid try/except/finally (and try/except/else/finally) blocks. parser.tuple2ast fails with: parser.ParserError: Illegal number

[issue1757118] utilize 2.5 try/except/finally in contextlib

2007-08-23 Thread Georg Brandl
Georg Brandl added the comment: Committed in rev. 57331. -- assignee: - gbrandl nosy: +gbrandl resolution: - accepted status: open - closed _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1757118 _

try...except...finally problem in Python 2.5

2007-02-14 Thread redawgts
I keep getting this error local variable 'f' referenced before assignment in the finally block when I run the following code. try: f = file(self.filename, 'rb') f.seek(DATA_OFFSET) self.__data = f.read(DATA_SIZE) self.isDataLoaded = True

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Jean-Paul Calderone
On 14 Feb 2007 11:41:29 -0800, redawgts [EMAIL PROTECTED] wrote: I keep getting this error local variable 'f' referenced before assignment in the finally block when I run the following code. try: f = file(self.filename, 'rb') f.seek(DATA_OFFSET)

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Robert Kern
redawgts wrote: I keep getting this error local variable 'f' referenced before assignment in the finally block when I run the following code. try: f = file(self.filename, 'rb') f.seek(DATA_OFFSET) self.__data = f.read(DATA_SIZE)

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Andrew Koenig
redawgts [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I keep getting this error local variable 'f' referenced before assignment in the finally block when I run the following code. try: f = file(self.filename, 'rb') f.seek(DATA_OFFSET)

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Larry Bates
redawgts wrote: I keep getting this error local variable 'f' referenced before assignment in the finally block when I run the following code. try: f = file(self.filename, 'rb') f.seek(DATA_OFFSET) self.__data = f.read(DATA_SIZE)

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Paul Rubin
redawgts [EMAIL PROTECTED] writes: try: f = file(self.filename, 'rb') ... Can someone tell me what's wrong with the code? Various people have explained the error: if the file open attempt fails, f is never assigned. Doing it the right way (i.e. handling the potential

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread redawgts
Thanks everybody, that helped alot. -- http://mail.python.org/mailman/listinfo/python-list

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Steven D'Aprano
On Wed, 14 Feb 2007 12:09:34 -0800, Paul Rubin wrote: redawgts [EMAIL PROTECTED] writes: try: f = file(self.filename, 'rb') ... Can someone tell me what's wrong with the code? Various people have explained the error: if the file open attempt fails, f is never

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: self.isDataLoaded = False try: f = open(self.filename, 'rb') f.seek(DATA_OFFSET) self.__data = f.read(DATA_SIZE) self.isDataLoaded = True except: pass else: pass (apart from being four lines shorter) Your version never

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Steven D'Aprano
On Wed, 14 Feb 2007 18:03:19 -0800, Paul Rubin wrote: Steven D'Aprano [EMAIL PROTECTED] writes: self.isDataLoaded = False try: f = open(self.filename, 'rb') f.seek(DATA_OFFSET) self.__data = f.read(DATA_SIZE) self.isDataLoaded = True except: pass else: pass

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Steven D'Aprano
Replying to my own question... On Thu, 15 Feb 2007 13:17:00 +1100, Steven D'Aprano wrote: I don't see where the with version closes the file either. How does it know that I want to call the f's close() method, rather than, say, f.exit() or f.do_something_else()? Ah, I *think* I see... file

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: Yes it does. Eventually f goes out of scope and is closed automatically. Oh right, however you can't really predict when the closure occurs, unless you're relying on current CPython artifacts. Re your other post: yes, PEP 363 explains how the with

Re: try...except...finally problem in Python 2.5

2007-02-14 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes: Re your other post: yes, PEP 363 explains how the with statement Whoops, 343. -- http://mail.python.org/mailman/listinfo/python-list

[ python-Bugs-1453570 ] try-except-finally in the tutorial

2006-03-19 Thread SourceForge.net
thread, including the initial issue submission, for this request, not just the latest update. Category: Documentation Group: Python 2.5 Status: Closed Resolution: Fixed Priority: 5 Submitted By: George Yoshida (quiver) Assigned to: Nobody/Anonymous (nobody) Summary: try-except-finally in the tutorial

[ python-Bugs-1453570 ] try-except-finally in the tutorial

2006-03-18 Thread SourceForge.net
of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Documentation Group: Python 2.5 Status: Open Resolution: None Priority: 5 Submitted By: George Yoshida (quiver) Assigned to: Nobody/Anonymous (nobody) Summary: try-except-finally

Exception handling code (try/except/finally)

2005-03-07 Thread djw
c.l.p- I am having trouble understanding how one is supposed to correctly utilize try:...except:...finally: in real code. If I have a block of code like: def foo(): try: ... some code that can raise an exception ... finally: ... do some cleanup

Re: Exception handling code (try/except/finally)

2005-03-07 Thread Michael Hoffman
djw wrote: c.l.p- I am having trouble understanding how one is supposed to correctly utilize try:...except:...finally: in real code. If I have a block of code like: def foo(): try: ... some code that can raise an exception ... finally: ... do some cleanup