why no ++?

Andrew Dalke dalke at acm.org
Sun Aug 19 08:07:30 EDT 2001


Bernd Nawothnig:
>Hmm, without having true symbol-expressions (lvals speaken in C-ish) it
>makes no difference which of the different symbols is bound physically
first
>to a value because there can't be any side effect.

Not quite.  You assume the left side is assignable.

>>> file = open("/etc/passwd")
>>> a, file.b, c = 1, 2, 3
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: b
>>> a
1
>>> b
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'b' is not defined
>>> c
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'c' is not defined
>>> class NoAssign:
...   def __setattr__(self, name, val):
...     raise AssertionError
...
>>> a, NoAssign().b, c = 1, 2, 3
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in __setattr__
AssertionError
>>> a
1
>>> c
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'c' is not defined
>>>

>Is there a possibility in Python to return a symbol? In other words: is it
>possible to write:
>
>a() = 5

No.

>>> a() = 1
SyntaxError: can't assign to function call
>>>
                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list