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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Jun 15 01:42:14 CEST 2008


Cesare Di Mauro wrote:

> However, I don't agree with the FAQ on this point. I think that a
 > Pascal-like with statement can be achieved, even with a dynamic
 > language such as Python, and in a simple way.

It's not so much a matter of whether it *can* be done, but
whether there's any substantial need for it. I don't believe
there is in Python, because you can always put a reference
to the target object into a succinctly-named local and access
it through that.

You can't always do that in Pascal, because it provides no
way of obtaining a pointer a record that wasn't heap-allocated.

-- 
Greg


More information about the Python-Dev mailing list