1

I want to print a string buffer (or byte array) which could contains some special characters, such as \t and \n, besides that, I need to print some indicators below the line to indicate some special part of the string, something like below:

a b c d \t , e f g \n 
  ~~~~~~~~   ^^^^^

Here is the questions:

1, the escape char and the normal char should be printed in a fixed width, but I see that repr() function can not.

2, some indicator below the first line should be printed.

3, if we still use repr() function, then I think the marker in the second line should be calculated dynamically, because repr() don't print texts in a fixed width format, thus a \t takes two chars.

Any one can help?

BTW: the whole idea is that I want to create a python pretty printer for GDB to show a token when debugging a parsing algorithm.

EDIT: Here is an example:

print (repr("abcd\t,efg\n"))

when you run the code, you get a printed string which has 12 element instread of 10, for me, ff I want to hight the token "efg", which is the index 6,7,8 in the string, if I draw a markers in the second from the index 6,7,8, I get the following.

abcd\t,efg\n
      ~~~

Because the "\t" has two chars not the one, which means the function repr() don't print fixed witdh chars, in this case, I would like to see:

abcd\t,efg\n
       ~~~
ollydbg23
  • 1,124
  • 1
  • 12
  • 38
  • This link may help you: [Print in terminal with colors using Python](http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python) – Huan-Yu Tseng Apr 23 '15 at 03:20
  • "thus a `\t` takes two chars." -- The alternative is a literal tab, which takes any of 2, 4, or 8 spaces, depending on who's displaying it. What would you have `repr()` do instead? – Kevin Apr 23 '15 at 03:56
  • Hi, Kevin, I have make an example to my question – ollydbg23 Apr 23 '15 at 09:28

0 Answers0