Saturday 15 March 2014

python - How can I display out-of-range ascii characters? -


I am connected to a Linux machine by virtue.

On a Linux machine, I'm running a dragon script that takes a list of letters and prints each character with its index.

Some of the letters from my list come out of printable ascii characters limit, these irregular characters are corrupting my output. Sometimes they simply do not appear, while the second time they actually remove large amounts of legitimate text.

I thought I can correct it by closing buffering, but the problem is also when I try to script the Python -u flag.

Interestingly, this problem does not occur when I pipe my input for less reader. Less, irregular characters appear like this: & lt; A9 & gt; , & lt; A7 & gt; There is no limit to the text of , ^ V , ^ @ , etc.

I'm not sure where my problem is, is there a way to configure my terminal so that unpiped output will still show random characters?

You have less ASCII characters representing these non-printable characters Configurable to display raw characters in the form of combinations; -r or - raw-control-chars The command line switch does this:

Due to the "raw" control character being displayed Displaying control characters by using carat notation is the default; For example, a control-A (Octa 001) is displayed as "^ A". WARNING: When the -r option is used, the actual appearance of the screen can not be underestimated (because it reacts on each type of control character to the screen). Thus, there may be the result of various performance issues, such as the wrong location divided incorrectly.

This is a special low feature.

If you want to do this with your Python program, then you have to do the same translation yourself. Make 'special' characters change in the applying code mapping:

  nonprintable = {'\ x00': '^ @', '\ x01': '^ A', '\ x02': I (128) for category: 'B', '\ x03': '^ C', '\ x04': '^', # etc}: character = chr (i) print i, nonprintable.get (character , Character)    

No comments:

Post a Comment