Can't do a multiline assignment!
Sion Arrowsmith
siona at chiark.greenend.org.uk
Thu Apr 17 13:07:21 EDT 2008
<s0suk3 at gmail.com> wrote:
>In Python, you usually can use parentheses to split something over
>several lines. But you can't use parentheses for an assignment of
>several lines.
Yes you can, you just need an iterable of the right length on
the other side for the tuple unpacking to work:
>>> (CONSTANT1,
... # This isn't a syntax error
... CONSTANT2,
... CONSTANT3, #and neither is this
... CONSTANT) = [1] * 4
>>> [ (k, v) for k, v in locals().items() if k.startswith("CONSTANT") ]
[('CONSTANT', 1), ('CONSTANT1', 1), ('CONSTANT3', 1), ('CONSTANT2', 1)]
>>>
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list