MCPcopy Create free account
hub / github.com/ipython/ipython / remove_comments

Function remove_comments

IPython/core/inputsplitter.py:246–261  ·  view source on GitHub ↗

Remove all comments from input source. Note: comments are NOT recognized inside of strings! Parameters ---------- src : string A single or multiline input string. Returns ------- String with all Python comments removed.

(src)

Source from the content-addressed store, hash-verified

244
245
246def remove_comments(src):
247 """Remove all comments from input source.
248
249 Note: comments are NOT recognized inside of strings!
250
251 Parameters
252 ----------
253 src : string
254 A single or multiline input string.
255
256 Returns
257 -------
258 String with all Python comments removed.
259 """
260
261 return re.sub('#.*', '', src)
262
263
264def get_input_encoding():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected