Michael Hudson wrote:

> Looking at my above code, no (even though I think I've rendered the
> point moot...).  Compare and contrast:
>
> @template
> def redirected_stdout(out):
>     save_stdout = sys.stdout
>     sys.stdout = out
>
>     yield None
>
>     sys.stdout = save_stdout
>
> class redirected_stdout(object):
>
>     def __init__(self, output):
>         self.output = output
>
>     def __enter__(self):
>         self.save_stdout = sys.stdout
>         sys.stdout = self.output
>
>     def __exit__(self):
>         sys.stdout = self.save_stdout
>
> The former is shorter and contains less (well, no) 'self.'s, but I
> think I find the latter somewhat clearer.

the same argument could be used (and was probably used) against
generators: why not just use __getitem__ and instance state?

as soon as you write something longer than four lines, using more
than one state variable, you'll find that generator-based code is a
lot more readable.

</F>



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to