Aaron Bentley wrote:
> Jeroen Vermeulen wrote:
>> Aaron Bentley wrote:
>
>>> ISTM that try/finally is just syntactic sugar for try/except+raise/else,
>>> and that context managers handle the latter just fine.
>> But to my taste not very transparently, is my point.
>
> On the other hand, context m
Aaron Bentley wrote:
One alternative to using a context manager for transactions is:
txn = transaction.begin()
try:
modify_the_database()
finally:
# Ah, everything succeeded.
txn.commit()
Gah! The horror!
Jeroen
_
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Jeroen Vermeulen wrote:
> Aaron Bentley wrote:
>
>> ISTM that try/finally is just syntactic sugar for try/except+raise/else,
>> and that context managers handle the latter just fine.
>
> But to my taste not very transparently, is my point.
On the ot
Aaron Bentley wrote:
ISTM that try/finally is just syntactic sugar for try/except+raise/else,
and that context managers handle the latter just fine.
But to my taste not very transparently, is my point.
Jeroen
___
Mailing list: https://launchpad.ne
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256
On Feb 11, 2010, at 12:22 PM, Aaron Bentley wrote:
>> txn = transaction.begin()
>> try:
>> modify_the_database()
>> except:
>> # Yes, bare except.
>> txn.abort()
>
>I would usually have a raise here.
Yep, silly o
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Barry Warsaw wrote:
> I'm not sure the with-statement was designed for transactions, but one good
> reason why it shouldn't be used for transactions is because (IME) proper
> handling doesn't fit into pure try/finally:
>
> txn = transaction.begin
On Feb 11, 2010, at 02:48 PM, Jeroen Vermeulen wrote:
>Barry Warsaw wrote:
>> >>> with open('/etc/passwd') as a, open('/etc/group') as b:
>> ... pass
>
>That's very good news! And this presumably takes care of the "what if
>the second open() fails" and "what if b's cleanup depends o
On Feb 11, 2010, at 07:38 AM, Robert Collins wrote:
>On Wed, 2010-02-10 at 14:42 -0500, Barry Warsaw wrote:
>>
>> with cwd('/path/to/stuff'):
>> # ...
>>
>> is pretty obvious.
>
>And extremely dangerous, as well as trivially broken. Not safe to use
>from any server code.
Any more so
Barry Warsaw wrote:
it doesn't scale well for more than resource;
'one'?--^
Indeed.
>>> with open('/etc/passwd') as a, open('/etc/group') as b:
... pass
That's very good news! And this presumably takes care of the "what if
the second open() fails
On Thu, 11 Feb 2010 09:38:11 Robert Collins wrote:
> On Wed, 2010-02-10 at 14:42 -0500, Barry Warsaw wrote:
> > with cwd('/path/to/stuff'):
> > # ...
> >
> > is pretty obvious.
>
> And extremely dangerous, as well as trivially broken. Not safe to use
> from any server code.
>
> (And i
On Wed, 2010-02-10 at 14:42 -0500, Barry Warsaw wrote:
>
> with cwd('/path/to/stuff'):
> # ...
>
> is pretty obvious.
And extremely dangerous, as well as trivially broken. Not safe to use
from any server code.
(And if its not obvious why its dangerous or breakable, that should
serve
On Feb 10, 2010, at 05:28 PM, Bjorn Tillenius wrote:
> think we should be a bit careful using it for other things than files.
>I'm sure there are good use cases for using with with custom
>implementations, but we should be careful not to over-use it. Just
>because it's easy to write, doesn't mean
On Feb 02, 2010, at 06:21 PM, Jeroen Vermeulen wrote:
>(Irrelevant gripes: it's a thin layer of sugar;
True, but it's a tasty bit of sugar. I find that carefully used,
with-statements are more readable than try/finallys.
>it doesn't scale well for more than resource;
'one'?-
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Bjorn Tillenius wrote:
> As I see it, the with statement is
> mainly useful wehre you have a well-known behaviour, where it's easy to
> find out what's going on (for example from the name), or when the
> clean-up step isn't important.
Why do you say "
On Wed, Jan 27, 2010 at 12:31:04PM -0500, Barry Warsaw wrote:
> Now that we're on Python 2.5, we have a few new language features at our
> disposal. In today's AMEU reviewer meeting, I brought up the 'with' statement
> and was asked to write something up about it. The with statement will be okay
Barry Warsaw wrote:
A common question is whether to use these to manage transactions. Jeroen and
I have debated this one. It's worked well for me in my Storm-based
non-Launchpad applications, but Jeroen doesn't like their semantics for this.
I'll let him take it from there.
I've got nothing
On Wednesday 27 January 2010 17:31:04 Barry Warsaw wrote:
> Now that we're on Python 2.5, we have a few new language features at our
> disposal. In today's AMEU reviewer meeting, I brought up the 'with'
> statement and was asked to write something up about it. The with
> statement will be okay
Now that we're on Python 2.5, we have a few new language features at our
disposal. In today's AMEU reviewer meeting, I brought up the 'with' statement
and was asked to write something up about it. The with statement will be okay
to use in Launchpad code, so you'll see more of it crop up, and it's
18 matches
Mail list logo