[Python-Dev] SyntaxError: can't assign to function call (original) (raw)
Neal Becker ndbecker2 at gmail.com
Wed Aug 9 20:10:15 CEST 2006
- Previous message: [Python-Dev] SyntaxError: can't assign to function call
- Next message: [Python-Dev] SyntaxError: can't assign to function call
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Terry Reedy wrote:
"Neal Becker" <ndbecker2 at gmail.com> wrote in message news:ebd2sp$nnv$1 at sea.gmane.org... class X (object): pass
X() += 2
SyntaxError: can't assign to function call Suppose I actually had defined iadd for class X. Python says this syntax is invalid. I wish is wasn't. If you translate to x() = x() +2, with x called just once, it does not make sense. You can bind to names and slots in compound objects, but not to objects. Here's where I might use it. Suppose I have a container class. Suppose I could make a slice of this container, like so: c = Container() s = Slice (c, 0, 10) where "Slice" is a class. Then: s += 2 Would perform iadd on the slice of the container. A convenient syntax would be: Slice (c, 0, 10) += 2 If this were made to work, the unbound object you are making an 'assignment' to, purely for side effect, would disappear. So if you don't want a separate object to be named and kept around, give your container a sliceadd method: c.sliceadd((0,10), 2) Does anyone else think this would be a good addition to Python? I don't. Augmented assigment is confusing enough to many.
I guess I confused things with the augmented assignment. It's not a question specific to augmented assignment. There are 2 questions:
- Should assignment to a temporary object be allowed?
- Should the syntax for creation of a temporary object be a constructor call?
- Previous message: [Python-Dev] SyntaxError: can't assign to function call
- Next message: [Python-Dev] SyntaxError: can't assign to function call
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]