0

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?

Community
  • 1
  • 1
Lingnik
  • 144
  • 7

2 Answers2

1

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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
1

It's the default comment marker in SciTE.

Default settings have:

comment.block.python=#~

And yes, it's a purely aesthetic choice.

ionelmc
  • 720
  • 2
  • 10
  • 29