1

I know that in regular lines it can do this

#print "Comment Line."   

and the whole line is a comment

But I want to comment a "define line" in Python.
For example

# -*- coding: utf-8 -*- 

I thought it will "comment" the whole line, so the interpreter will ignore it, but it's not what happen. The interpreter refer to it as"regular define

In C if I remember it right it's simple, and it's something like this

//#define Hello Holly

But how can I do that in Python?

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Matt. Stroh
  • 904
  • 7
  • 16
  • I haven't tested, but what happens if you add an extra `#` to the beginning of the line? – zondo May 17 '16 at 22:18
  • I tried it, but the line wasn't been ignored, nothing really happend – Matt. Stroh May 17 '16 at 22:19
  • Just in case there are any "duplicate" flags inbound... This is _not_ a duplicate of "[Multiline comments in Python](https://stackoverflow.com/questions/7696924)", because this question is (unwittingly) about behavior _specific to [`coding` comments](http://www.python.org/dev/peps/pep-0263/)_ when they appear on the first or second line of a `.py` file, and not to any other comments. Matt. St's question about a multi-line comment syntax is really an attempt to work around this one special comment syntax. – Kevin J. Chase May 18 '16 at 01:40

2 Answers2

4

There's no such thing as a "define line" in Python. The coding thing you show is already a comment, but it's a comment with special interpretation.

If you want to prevent a coding comment from taking effect without removing it, move it down to the third line of the file or lower by inserting blank lines or more comments above it.

user2357112
  • 260,549
  • 28
  • 431
  • 505
  • thanks, it does help. though I have a new question, does moving lines with "comment with special interpretation" to the third line make them to be ignored? or it's just `coding` ? – Matt. Stroh May 17 '16 at 22:30
  • @Matt.St: This is specific to Python's handling of `coding` comments. I don't know of any other comments that Python treats specially, but there are comments like shebang lines that get interpreted by other systems and follow different rules. – user2357112 May 17 '16 at 22:35
-1

I think /* and */ might be block-all comments, but if not, docstrings (triple quotes) are.

Owen Hempel
  • 434
  • 2
  • 8