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

Simon Cross hodgestar+pythondev at gmail.com
Sat Jun 14 11:03:09 CEST 2008


On Sat, Jun 14, 2008 at 10:16 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> I am a great fan of Pascal-style with blocks, and I'd love Python to get
> something like them. But I have concluded that they simply aren't
> practical in Python. Your suggestion sounds reasonable at first glance,
> but it isn't really.
>
> def foo(a):
>    on a:
>        x = round(x, n)
>    return x
>
> What does this function do? There's no way of telling, because it
> depends on what attributes a has. It might be equivalent to any of:

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


More information about the Python-Dev mailing list