Embedded comments in Python?

Michael Chermside mcherm at mcherm.com
Mon May 3 14:27:14 EDT 2004


Ernie writes:
> Whats the legal way in Python to embed comments in Python code?
    [...]
> In C/C++, this would be no problem with /* */.

Python has no way of producing these sorts of comments.[1] I
suggest putting the comments either above the line or below it.
In the case of type specifications, I suggest describing the
expected types in your docstring, unless you use a framework
to actually validate the types, in which case the format you
use will depend on the framework.

-- Michael Chermside

[1] - Well, almost. I suppose there *IS* actually a way of inserting
a comment between two Python tokens. Simply preceed the comment
with "\\\n#" (a backslash, a newline, and a hash) and follow it with
"\\\n" (a backslash and a newline). I *think* this works between
any two tokens... right?




More information about the Python-list mailing list