You can find all the instruction commands in the wiki page I linked earlier. \x1b8: The instruction "8" means restore the cursor information.No escape character here, so the text is printed normally. %s: This is replaced by the text from the user.Your code replaces the %ds with numbers inputted by the user. \x1b[%d ?: The instruction "[10 10f" means go to row 10, column 10.The most important one may be n which indicates a new line. \x1b7: The instruction "7" means save the cursor information. In Python, escape sequences are indicated by a backslash ( ).When the terminal encounters a \x1b escape character it knows that the information following it is an instruction for the terminal, not to be printed. Without using an escape sequence, Python would interpret the tab as whitespace. This character happens to be named "ESC" and it's being used as an escape character for ANSI, don't confuse it with python's escape character: the backslash ( \). For example, lets say you want to print a string that contains a tab character. The "1b" is hexadecimal for 27: > int('1b', 16)Īnd if you look up 27 on an ASCII table you will find that it corresponds to the ESC character. Escape Sequence or Escape Character is used to signal an alternative interpretation of a series of characters. Another escape sequence worth mentioning is \' for a single quote within a string. Like so, multiple logical lines can be stacked into a single physical line. The most important one may be which indicates a new line. \x1b is the way python displays the ESC character. Escaping in Python In Python, escape sequences are indicated by a backslash ( \ ).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |