0

Whenever I try to print out the ascii values of for example DEC 127( : DEL) I get a box with a diagonal line box which is shown when character could not get recognized means it doesn't get recognized but as soon as I copy these boxes and paste them into PyCharm(2021.2.3) I get the letters "DEL". Another example is, if I print out DEC 10( : LF) what is equal to "\n" it just prints out the new line. So my Question:

Is there any way I can print "DEL" and "LF" instead of the boxes?

Here is the code I use:

for i in range(128)
    ascii_table[str(i)] = chr(i)

And then I display it with:

ascii_table_width = 10
for key, item in ascii_table.items():
    print(f"{key} : {item}", end=" | ")
    if int(key) % ascii_table_width == 0:
        print("\n")

And even weirder is, if I display it with:

print(ascii_table)

I get as the value of the key "127" a string with the escape character(\) and after that the corresponding value of DEL: '\x7f'. For 10 it is '\n'. This better than the box but still not what I want. I want to have DEL and LF to show up.

The thing is, that when I do this:

print(ascii_table["127"])

it definitely should print out '\x7f' like before but no, it prints out the box again.

And if I run

>>>print(chr(1)) 

in python inside the Command Prompt I even get a smiley instead of the box and for 127 it is a symbol that looks like a house. For 10 it is just a new line.

I just find it really interesting. Does anyone has an explanation for this phenomenon?

Pixelbog
  • 236
  • 1
  • 8
  • Read the following through to see if anything suits your needs: https://stackoverflow.com/questions/13927889/show-non-printable-characters-in-a-string – PM 77-1 Nov 24 '21 at 16:43
  • By *command prompt* do you mean the [console](https://www.jetbrains.com/help/pycharm/interactive-console.html) or the [terminal](https://www.jetbrains.com/help/pycharm/terminal-emulator.html)? You question is about setting the encoding of the terminal/console to have the right code pages, you ask *" I can print "DEL" and "LF" instead of the boxes?"* those characters get printed according to their encoding. If you want to print them in a costum way then use an equivalent in the print. – bad_coder Nov 24 '21 at 16:58
  • Does this answer your question? [How to get PyCharm to display unicode data in its console?](https://stackoverflow.com/questions/14188655/how-to-get-pycharm-to-display-unicode-data-in-its-console) – bad_coder Nov 24 '21 at 17:00
  • Also see [this post](https://stackoverflow.com/q/30257580) – bad_coder Nov 24 '21 at 17:01
  • You see something like `☺☻♥♦♣♠␍␊♂♀♫☼►◄↕‼¶§▬↨↑↓→∟↔▲▼` in [Code Page 437](https://en.wikipedia.org/wiki/Code_page_437#Character_set). Switch to [UTF-8 Everywhere](https://utf8everywhere.org/). – JosefZ Nov 24 '21 at 17:16
  • Thank you for everyone who commented I have read every link you guys linked and that helped me a lot. Thanks! :) – Pixelbog Nov 25 '21 at 20:00

0 Answers0