Re: Missing something on exception handling in Python 3

2013-08-27 Thread Steven D'Aprano
On Tue, 27 Aug 2013 00:00:36 -0500, Skip Montanaro wrote: > I found this question/answer on Stack Overflow: > > http://stackoverflow.com/questions/15123137 > > but after fiddling around with it, I can't find a solution that works > for Python 3.2 and 3.3, let alone 2.x. In 3.2, exceptions have

Re: Missing something on exception handling in Python 3

2013-08-26 Thread Skip Montanaro
I found this question/answer on Stack Overflow: http://stackoverflow.com/questions/15123137 but after fiddling around with it, I can't find a solution that works for Python 3.2 and 3.3, let alone 2.x. In 3.2, exceptions have both __cause__ and __context__ attributes. I tried setting both to Non

Re: Missing something on exception handling in Python 3

2013-08-26 Thread Ethan Furman
On 08/26/2013 07:49 PM, Skip Montanaro wrote: Do this: raise LockFailed("Failed to create %s" % self.path) from None Thanks. Is there some construct which will work in 2.x and 3.x? Something like this (untested): exc = None try: write_pid_to_lockfile(somefile) excep

Re: Missing something on exception handling in Python 3

2013-08-26 Thread Skip Montanaro
> Do this: > > raise LockFailed("Failed to create %s" % self.path) from None Thanks. Is there some construct which will work in 2.x and 3.x? Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Missing something on exception handling in Python 3

2013-08-26 Thread MRAB
On 27/08/2013 02:48, Skip Montanaro wrote: I have code in the pylockfile package that looks roughly like this (apologies for the indentation - I'm growing to dislike Gmail for typing code fragments): try: write_pid_to_lockfile(somefile) except OSError as exc: if conditions_i_can_handle

Missing something on exception handling in Python 3

2013-08-26 Thread Skip Montanaro
I have code in the pylockfile package that looks roughly like this (apologies for the indentation - I'm growing to dislike Gmail for typing code fragments): try: write_pid_to_lockfile(somefile) except OSError as exc: if conditions_i_can_handle: do_other_stuff... else: ra