Python dot-equals (syntax proposal)

Brendan Abel 007brendan at gmail.com
Fri Apr 30 22:09:00 CEST 2010


On Apr 30, 9:04 am, Jabapyth <jabap... at gmail.com> 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?

I tend to use this design pattern occasionally in my code as well:

val = val.func()  PROPOSED:  val .= func()

OR

val = func(val)  PROPOSED: val .= func(?) (not really sure how this
should look)


However, these are the only two use cases I can think of for this
language syntax modification proposal.  The first use case could lead
to namespace issues (if func() exists as a function as well as a
method), and even if the interpreter can choose correctly, reading it
may lead to confusion.  There will be at least some ambiguity in the
second use case (what if func() takes more than one argument, what if
it requires keyword arguments?).  The current implementation is much
more readable (THE guiding principle with python), and doesn't require
any lengthier code than the proposed changes, especially when you
factor in any other syntax changes that would be necessary to handle
the aforementioned ambiguities.

Just my 2 cents. :)



More information about the Python-list mailing list