I know that Python does not support multi-line comments, because they can render the code unreadable. I have a proposal that could fix this problem.
Consider this code:
a = (1, 4, 7)
for x in a:
print(x)
for i, y in enumerate(a):
print("{}: {}".format(i+1, y))
I decide to comment the first for
loop. Well, I could do this:
a = (1, 4, 7)
/*
TODO fix it before restore it
for x in a:
print(x)
*/
for i, y in enumerate(a):
print("{}: {}".format(i+1, y))
Notice that:
-
a blank line is required before
/*
and after*/
, and a newline character is required after/*
and before*/
. (edit: only space and tabs are allowes after/*
and*/
) -
/*
and*/
are at the same level of the code (edit: and the level must be the lowest column of the commented block). For example, you can’t do this:
a = (1, 4, 7)
for x in a:
print(x)
/*
print(x*x)
for i, y in enumerate(a):
print("{}: {}".format(i+1, y))
*/
EDIT: but you can do this:
a = (1, 4, 7)
for x in a:
print(x)
/*
print(x*x)
for i, y in enumerate(a):
print("{}: {}".format(i+1, y))
*/
I think in this way a coder can use a multiline comment that is readable, without using the ugly trick of using the multistring…
PS: I must say I preferred to use ###
, but it’s not retro-compatible.