A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2005-May/053717.html below:

[Python-Dev] Merging PEP 310 and PEP 340-redux?

[Python-Dev] Merging PEP 310 and PEP 340-redux? [Python-Dev] Merging PEP 310 and PEP 340-redux?Fredrik Lundh fredrik at pythonware.com
Fri May 13 18:42:56 CEST 2005
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>



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4