Python dot-equals (syntax proposal)

Albert van der Horst albert at spenarnc.xs4all.nl
Sun May 2 08:12:23 EDT 2010


In article <mailman.2429.1272646255.23598.python-list at python.org>,
Jean-Michel Pichavant  <jeanmichel at sequans.com> wrote:
>Jabapyth wrote:
>> At least a few times a day I wish python had the following shortcut
>> syntax:
>>
>> vbl.=func(args)
>>
>> this would be equivalent to
>>
>> vbl = vbl.func(args)
>>
>> example:
>>
>> foo = "Hello world"
>> foo.=split(" ")
>> print foo
>> # ['Hello', 'world']
>>
>> and I guess you could generalize this to
>>
>> vbl.=[some text]
>> #
>> vbl = vbl.[some text]
>>
>> e.g.
>>
>> temp.=children[0]
>> # temp = temp.children[0]
>>
>> thoughts?
>>
>Useless if you use meaningful names for your variables & attributes.
>
>It may happen that one object attribute refer to an object of the same
>type, but it is quite rare that both can share the same name anyway.
>
>Possible use cases:
>
>1/
>car = Car()
>car = car.wheel # ???
>
>2/
>wheel = Car() # ???
>wheel = wheel.wheel # ???
>
>3/
>currentCar = Car()
>currentCar = currentCar.nextCar
>
>The syntax you prose will be applicable on very little assignements (use
>case 3). I'm not sure it's worth it.

Note how related it is to the requirement to have a _radd_ operator.

It amounts to the argument that
        a op= b
requires that a and b have somewhat "similar" "type", or that
the "type" of a doesn't really change as a result from the operation.

This is IMHO an argument against the .= pseudo-operator.

>
>JM

Groetjes Albert

--
-- 
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert at spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst




More information about the Python-list mailing list