pretty print - Python printing text: Highlight or mark some text in the string with indicators -


i want print string buffer (or byte array) contains special characters, such \t , \n, besides that, need print indicators below line indicate special part of string, below:

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

here questions:

1, escape char , normal char should printed in fixed width, see repr() function can not.

2, indicator below first line should printed.

3, if still use repr() function, think marker in second line should calculated dynamically, because repr() don't print texts in fixed width format, \t takes 2 chars.

any 1 can help?

btw: whole idea want create python pretty printer gdb show token when debugging parsing algorithm.

edit: here example:

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

when run code, printed string has 12 element instread of 10, me, ff want hight token "efg", index 6,7,8 in string, if draw markers in second index 6,7,8, following.

abcd\t,efg\n       ~~~ 

because "\t" has 2 chars not one, means function repr() don't print fixed witdh chars, in case, see:

abcd\t,efg\n        ~~~ 


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -