[Python-Dev] Python FAQ: Why doesn't Python have a "with" statement?

Cesare Di Mauro cesare at pronto.it
Sat Jun 14 21:53:14 CEST 2008

In data 14 giugno 2008 alle ore 11:03:09, Simon Cross <hodgestar+pythondev at gmail.com> ha scritto:

> After having read all the examples in the thread so far, let's never
> add anything like this to Python ever. It breaks so many of the
> "import this" guidelines it's scary. The biggest loss is readability.
> Sure in a statically typed language it might be possible for the
> compiler figure out which things are attributes and which are not, but
> I have to be able to do the same. And lets not even think about what
> happens when some adds a new attribute to a and code using "on a"
> suddenly starts silently breaking.
> Schiavo
> Simon

It was just a "rough" idea, and I have suggested two solutions to make it better.

Obviously there can be situations where the new instruction will be useful, and other where it will not.

In my experience I found so many times coding "patterns" where I work "inside" an object,
calling many methods and accessing its variabiles (primarily reading them),
and the new instruction which I proposed to have in Python can make this kind of code much easier
to write and managed (especially with GUIs, there are many common "patterns" that can benefit
from it).

Also, I think that the code can be more readable.
Just take a look at the example I reported: don't you find it easier to read?

Cesare Di Mauro

More information about the Python-Dev mailing list