[Python-Dev] Can we triple quoted string as a comment?
raymond.hettinger at gmail.com
Tue Mar 26 02:16:47 CET 2013
On Mar 25, 2013, at 2:16 PM, Victor Stinner <victor.stinner at gmail.com> wrote:
> I just realized that the Python peephole optimizer removes useless
> instructions like numbers and strings between other instructions,
> without raising an error nor emiting an error. Example:
> $ python -Wd -c 'print "Hello"; "World"'
IIRC, this happens upstream from the peephole optimizer
and has been a part of Python for a long time.
You can also "comment-out" code with "if 0:"
>>> def f(x):
>>> from dis import dis
4 0 LOAD_FAST 0 (x)
3 LOAD_CONST 1 (1)
> As part of my astoptimizer project, I wrote a function to detect such
> useless instructions which emit a warning. I opened the following
> issue to report what I found:
Make sure it is a warning you can turn-off.
I've seen code in many organizations that use multi-line
strings to "turn-off" a section of code but not actually remove the code
from the source.
> Different modules use long strings as comments. What is the "official"
> policy about such strings? Should we use strings or comments?
> (IMO a comment should be used instead.)
The module authors typically make their own decisions
with respect to readability and ease of commenting.
If you're editing with Emacs, it is really easy to reflow paragraphs
and to insert or remove multiline comments each prefixed with #.
But with other editors, it can be a PITA and a multiline string is
the easiest to maintain and works well when cutting-and-pasting
the comments from somewhere else.
I worry that because you just discovered this feature, the initial
reaction is that is a horribly wrong thing to do and should be
Instead, it would be better to live-and-let live.
No need for wholesale code changes or imposition
"you must do it the way I do it" policies.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev