Can't do a multiline assignment!

s0suk3 at s0suk3 at
Thu Apr 17 16:59:51 CEST 2008

I was shocked a while ago when a discovered that in Python you can't
do a multiline assignment
with comments between the lines.

For example, let's say I want to assign a bunch of variables to an
initial, single value. In C or a similar language you would do:

/* This is some constant */

/*This is yet some other constant */


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. For that, you can use the line continuation character

CONSTANT1    = \
CONSTANT2    = \
CONSTANT3    = \

But I realized that you can't do this:

CONSTANT1    = \
# Oops... syntax error
CONSTANT2    = \
CONSTANT3    = \ # This is also a syntax error
# And this too \

Does anyone know of a way to put the comments between lines like that?
I find this limitation very annoying.

More information about the Python-list mailing list