Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mid-line comment in Python?

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.

like image 483
wim Avatar asked Apr 11 '11 05:04

wim


People also ask

How do you comment between lines in Python?

Comment Syntax Comments in Python begin with a hash mark ( # ) and whitespace character and continue to the end of the line.

Can you do multiline comment in Python?

Unlike other programming languages Python doesn't support multi-line comment blocks out of the box. The recommended way to comment out multiple lines of code in Python is to use consecutive # single-line comments. This is the only way to get “true” source code comments that are removed by the Python parser.

How do you make comments in Python?

Python Comment Syntax. To add or mark a line as a comment, start with a hash sign (#) and a space: # This is a sample comment. Using the hash sign to start the line tells the system to ignore everything in that line.


2 Answers

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.

like image 64
James Khoury Avatar answered Oct 20 '22 08:10

James Khoury


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

like image 36
bradley.ayers Avatar answered Oct 20 '22 07:10

bradley.ayers