Do pythons like sugar?

Andrew Dalke adalke at mindspring.com
Thu Jan 9 05:25:41 EST 2003


Afanasiy wrote:
>>A few languages provide syntax sugar for dealing with
>>this by allowing you to localize the class scope.
>>
>>Does Python? eg. `with self do:`

> So the answer is a definitive no? I want to do things as I have them,
> I don't want to change my design just to be able to type 'self' less.

It's a definite no.  From previous accounts, said sugar is hiding
rat poison.  It's advantages are slight to its disadvantages.  Eg,
for your case it would have hid a poor implementation rather than
yield a better one.

When I do a lot of "self." references it's mostly with a set of
initializations.  In that case I just leave "self." in my paste
buffer.

> Is there any tricky one-liner that brings object members in scope?

Yes but I won't tell.  You shouldn't use it.


> P.S. The specific implementation above should be considered irrelevant.

In order to add a new feature, especially one which affect the
language like that, then you'll need to come up with a pressing example.

If there isn't one, then there's no need for a change, eh?

					Andrew
					dalke at dalkescientific.com





More information about the Python-list mailing list