[Python-ideas] A user story concerning things knowing their own names
Jim Jewett
jimjjewett at gmail.com
Sat Mar 19 02:58:21 CET 2011
On Fri, Mar 18, 2011 at 9:37 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
>> There's another pattern where all class attributes that have a certain
>> property are also collected in a per-class datastructure,
> I think __addtoclass__ could cover those as well,
> if you can arrange for the relevant objects to inherit
> from a class having an appropriate __addtoclass__
> implementation.
How do you put an attribute (such as __addtoclass__ ) on a name? Or
are you proposing that the actual pattern be something more like:
x=SpecialObj()
And that normal initiation be handled either later, or as part of the
SpecialObj initiation
x=SpecialObj()=5
or
x=SpecialObj(); x=5
or
x=SpecialObj(value=5)
Doing this for every name seems likely to be wasteful. Doing it only
for certain initial values seems too magical.
Doing it only for certain attributes -- there still needs to be a way
to mark them, and I suppose we're back to either a decorator or a
special assignment operator.
@decorated_implies_an_object
x=5
x:=5
What have I missed here?
-jJ
More information about the Python-ideas
mailing list