Mid-line comment in Python?

PythonSyntaxComments

Python Problem Overview


I'm wondering if there is any way to comment out part of a line, like you can do in c++ with /*this*/. The only comments I know about are # this which always goes to the end of the line and the """these""" ones, which do not work mid-line.

Example use-case: using subprocess and need to temporarily comment out an argument -p 0 from the list:

['../some/guy', '-m', '10', '-p', '0', '-n', '100', '-f', '/dev/stdout']

It would be nice to have a keyboard shortcut to comment out a selection, at the moment I just copy the whole line as below

#['../some/guy', '-m', '10', '-p', '0', '-n', '100', '-f', '/dev/stdout']
['../some/guy', '-m', '10', '-n', '100', '-f', '/dev/stdout']

I'm expecting a big fat 'no' but I suppose it doesn't hurt to ask, python has surprised me a few times before.

Python Solutions


Solution 1 - Python

Actually if you break your statement into multiple lines you can.

Something like:

['../some/guy', '-m', '10',# '-p', '0', '-n', '100', '-f', '/dev/stdout']

should work.

Solution 2 - Python

You are correct, the answer is a big fat NO.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwimView Question on Stackoverflow
Solution 1 - PythonJames KhouryView Answer on Stackoverflow
Solution 2 - Pythonbradley.ayersView Answer on Stackoverflow