Object's nesting scope

Carl Banks pavlovevidence at gmail.com
Thu Aug 27 10:34:17 EDT 2009


On Aug 26, 5:51 am, zaur <szp... at gmail.com> wrote:
> Hi folk!
>
> What do you think about idea of "object's nesting scope" in python?
>
> Let's imaging this feature, for example, in this syntax:
>
> obj=<expression>:
>      <body>
>
> or
>
> <expression>:
>    <body>
>
> That's means that result object of <expression> evaluation is used as
> nested scope for <body> evaluation.
>
> So is this idea useful?

It might be marginally useful to save typing.  The idea has been
discussed in various forms here quite a bit over the years.  I doubt
there's any chance it'll be accepted into Python, because it goes
against one of the main design points of Python: that attributes
should always be accessed explicitly.

Having said that, the syntax you propose is awful. :) Normally when
this is proposed they use a keyword such as "using":

p = Person()
using p:
    name = "Carl Banks"
    location = "Los Angeles"

or, perhaps to save a line (even though it'd be a minor syntax abuse):

using Person() as p:
    name = "Carl Banks"
    location = "Los Angeles"


Carl Banks



More information about the Python-list mailing list