Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add inline comments to multiline string assignments in python

How to add comments to multiline assignments in python, as is possible in C with the syntax:

char sc[] = "\x31\xdb"                  /* xor %ebx, %ebx       */
            "\x31\xc9"                  /* xor %ecx, %ecx       */
            "\xb8\x46\x00\x00\x00"      /* mov $0x46, %eax      */
            "\xcd\x80"                  /* int $0x80            */
            "\x31\xdb"                  /* xor %ebx, %ebx       */
            "\xb8\x01\x00\x00\x00"      /* mov $0x1, %eax       */
            "\xcd\x80";                 /* int $0x80            */

but the same in python, using escaped line breaks

sc = "\x31\xdb" \   # xor %ebx, %ebx
     "\x31\xc9" \   # xor %ecx, %ecx
     "…"
like image 651
YBW Avatar asked Feb 08 '13 19:02

YBW


People also ask

How do you insert multiline comments in Python code?

To comment out multiple lines in Python, you can prepend each line with a hash ( # ). With this approach, you're technically making multiple single-line comments.

How do you write multiple line comments and single line comments?

To implement multi line comments using # sign, we can simply depict each line of a multi line comment as a single line comment. Then we can start each line by using # symbol and we can implement multi line comments.


1 Answers

You can write

sc = ("\x31\xdb"      # xor %ebx, %ebx
      "\x31\xc9"      # xor %ecx, %ecx
      "…")

if you want.

like image 190
Pavel Anossov Avatar answered Oct 11 '22 16:10

Pavel Anossov