Lingnik
Lingnik

Reputation: 144

Is there special significance to a comment starting as #~ in Python?

What is this syntax used for in Python?:

#~ Lorem ipsum dolor sit amet

I've run into this syntax a few times, for example in this script as referenced in this answer. For example:

def gdbExecute(exp):
  #~ if gdb.VERSION.startswith("6.8.50.2009"):
      #~ return gdb.parse_and_eval(exp)
  # Work around non-existing gdb.parse_and_eval as in released 7.0
  gdb.execute("set logging redirect on")
  gdb.execute("set logging on")
  locrep = gdb.execute("%s" % exp, True, True)
  gdb.execute("set logging off")
  return locrep

I attempted this SymbolHound search, but only came up with ~100 additional references where it's being used, but no direct explanation. There seem to be some indications that it's used for internationalization or translation?

Upvotes: 0

Views: 269

Answers (2)

ionelmc
ionelmc

Reputation: 721

It's the default comment marker in SciTE.

Default settings have:

comment.block.python=#~

And yes, it's a purely aesthetic choice.

Upvotes: 1

Martijn Pieters
Martijn Pieters

Reputation: 1121524

There is no special meaning to Python for comments starting with #~.

This is in all likelyhood a 3rd party tool using the ~ for their own purposes. I suspect there is an IDE used here that implements use this to do one of the following:

  • a block-comment feature that lets you easily remove the commenting again, returning the lines to their formal state
  • tell the IDE that the commented-out line can still be highlighted as code
  • have the lines be executed when running with debugging enabled

or other such feature. Or it could just be a stylistic choice people make from time to time.

The comment style also shows up in Ruby code, so this is hardly unique to Python.

Upvotes: 1

Related Questions