From: Alf P. Steinbach on
* Robert Kern:
> On 2010-03-03 09:39 AM, Mike Kent wrote:
>> What's the compelling use case for this vs. a simple try/finally?
>>
>> original_dir = os.getcwd()
>> try:
>> os.chdir(somewhere)
>> # Do other stuff
>> finally:
>> os.chdir(original_dir)
>> # Do other cleanup
>
> A custom-written context manager looks nicer and can be more readable.
>
> from contextlib import contextmanager
> import os
>
> @contextmanager
> def pushd(path):
> original_dir = os.getcwd()
> os.chdir(path)
> try:
> yield
> finally:
> os.chdir(original_dir)
>
>
> with pushd(somewhere):
> ...
>
>
> I don't think a general purpose ScopeGuard context manager has any such
> benefits over the try: finally:, though.

class pushd( Cleanup ):
def __init__( self, path ):
original_dir = os.getcwd()
os.chdir( path )
self._actions.append( lambda: os.chdir( original_dir ) )


Disclaimer: haven't tested this, but it just occurred to me that for such small
init/cleanup wrappers the Cleanup class provides a nice alternative to
@contextmanager, as above: fewer lines, and perhaps even more clear code. :-)


Cheers,

- Alf
From: Gabriel Genellina on
En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach <alfps(a)start.no>
escribi�:

> Sorry, as with the places noted above, I can't understand what you're
> trying to say here.

Regarding your posts, neither can I. All the time. Sorry, deciphering your
posts would force me to spend much more time than available and I can't
afford that - so I'm blocking your messages from now on.

--
Gabriel Genellina

From: Alf P. Steinbach on
* Gabriel Genellina:
> En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach <alfps(a)start.no>
> escribi�:
>
>> Sorry, as with the places noted above, I can't understand what you're
>> trying to say here.
>
> Regarding your posts, neither can I. All the time. Sorry, deciphering
> your posts would force me to spend much more time than available and I
> can't afford that - so I'm blocking your messages from now on.


You could just ask if there was anything you didn't understand.

Even with as little you quote readers can see my approach to that problem: asking.

But your response, both the out of context quoting and your comment, seems
solely designed to convey a negative impression instead of addressing any
technical issue.


Cheers,

- Alf
From: Steve Holden on
Alf P. Steinbach wrote:
> * Gabriel Genellina:
>> En Thu, 04 Mar 2010 20:52:04 -0300, Alf P. Steinbach <alfps(a)start.no>
>> escribi�:
>>
>>> Sorry, as with the places noted above, I can't understand what you're
>>> trying to say here.
>>
>> Regarding your posts, neither can I. All the time. Sorry, deciphering
>> your posts would force me to spend much more time than available and I
>> can't afford that - so I'm blocking your messages from now on.
>
>
> You could just ask if there was anything you didn't understand.
>
> Even with as little you quote readers can see my approach to that
> problem: asking.
>
> But your response, both the out of context quoting and your comment,
> seems solely designed to convey a negative impression instead of
> addressing any technical issue.
>
This isn't an isolated case, Alf. Physician, heal thyself.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010 http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

From: ssteinerX on
On Mar 8, 2010, at 7:28 AM, Steve Holden wrote:

>>
>> But your response, both the out of context quoting and your comment,
>> seems solely designed to convey a negative impression instead of
>> addressing any technical issue.
>>
> This isn't an isolated case, Alf. Physician, heal thyself.

As far as I can tell, this happens on every thread Alf is involved in at one point or another. I'm sure it's "everyone else."

S

First  |  Prev  | 
Pages: 1 2 3 4 5 6 7 8 9 10 11
Prev: Few early questions on Class
Next: SOAP 1.2 Python client ?