-1

I have found a way to list all the alt codes but I want to put them in a table so it looks something like this.

This is what I have tried:

variable = -1
for i in range(55295):
     print("---------")
     variable = variable + 1
     print(str(variable) + "   " + chr(variable))

This code will print all the alt codes. To get it into a table I tried this. (It has a time delay)

import time
variable = -1
#for i in range(55295):
for i in range(15):
     print("---------")
     variable = variable + 1
     print(" | "+ str(variable) + " |  " + chr(variable) + " | ")
     time.sleep(0.0001)
print("---------------------------------------------------")

I have run out of ideas, can you help please?

(This is the first time i've asked a question on here.)

6
  • read stackoverflow.com/questions/12453799/… Commented Feb 9, 2018 at 10:39
  • 1
    Creating a table in python is probably not what you want. You want your output to be formatted like a table. Do a google search for "print table python". Or use additional packages to create an image of the table, save it to excel, etc.... Commented Feb 9, 2018 at 10:45
  • Where do you want to display this table? Python console or somewhere else? Commented Feb 9, 2018 at 10:46
  • Those old MS-DOS character codes cannot be printed the same way they could in the 1980s... If you really want to see them as they appear in your image, then look up the 21st century Unicode value for each one of them and use that code instead. Commented Feb 9, 2018 at 10:57
  • Would tabulate be sufficient or does it have to be a GUI? Commented Feb 9, 2018 at 11:00

2 Answers 2

0

You cannot print characters with such low codes on a 21st century system. The characters in the image are those that appeared on old MS-DOS systems (according to Wikipedia: Code Page 437). However, modern systems work with Unicode fonts, and the codes below 32 (space) are control codes, reserved for special purposes. The code 9, for example, inserts a Tab, and 10 puts the text cursor on a new line.

(This was also the case on those old systems but you could circumvent this by writing immediately into the video buffer. Nowadays, that is no longer an option on most computers.)

To get the modern equivalent of the old characters, you need a lookup list that translates them. I copied mine from the wiki page linked to above. Note that there is no official representation of the code 0000; I changed it to a space. This is only for the control codes below 32. There are a few codes above 126 that also may not show "correctly" (as in "not as on antique computers" 😄), but you can look them up on the wiki page.

To correctly align one- and two-digit numbers, use print formatting. Aligning can be done with functions such as rjust and .format; but, coming from a C background, I prefer what the documentation calls "Old style formatting" (https://docs.python.org/3/library/stdtypes.html#old-string-formatting).

cp437 = [0x0020, 0x263A, 0x263B, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, 0x25D8, 0x25CB,
         0x25D9, 0x2642, 0x2640, 0x266A, 0x266B, 0x263C, 0x25BA, 0x25C4, 0x2195, 0x203C,
         0x00B6, 0x00A7, 0x25AC, 0x21A8, 0x2191, 0x2193, 0x2192, 0x2190, 0x221F, 0x2194,
         0x25B2, 0x25BC]

for i in range(15):
     print("+----+-----+")
     print("| %2d |  %s  |" % (i, chr(cp437[i])))
print("+----+-----+")

This produces the following table:

+----+-----+
|  0 |     |
+----+-----+
|  1 |  ☺  |
+----+-----+
|  2 |  ☻  |
+----+-----+
|  3 |  ♥  |
+----+-----+
|  4 |  ♦  |
+----+-----+
|  5 |  ♣  |
+----+-----+
|  6 |  ♠  |
+----+-----+
|  7 |  •  |
+----+-----+
|  8 |  ◘  |
+----+-----+
|  9 |  ○  |
+----+-----+
| 10 |  ◙  |
+----+-----+
| 11 |  ♂  |
+----+-----+
| 12 |  ♀  |
+----+-----+
| 13 |  ♪  |
+----+-----+
| 14 |  ♫  |
+----+-----+
Sign up to request clarification or add additional context in comments.

Comments

0

You can try to use the pyplot table method: I have modified and extended your example code so that it looks like: import matplotlib.pyplot as plt

import time
variable = 96
chars = []

#for i in range(55295):
for i in range(26):
   print("---------")
   variable = variable + 1
   chars.append([str(variable), chr(variable)])
   print(" | "+ str(variable) + " |  " + chr(variable) + " | ")
   time.sleep(0.0001)

print("---------------------------------------------------")

plt.figure('Table')
plt.axis('off')

columns=['Alt Codes','Characters']

tab = plt.table(cellText=chars,loc='center',cellLoc='center',colLabels=columns)

plt.show()

The result looks like: png file of the table saved with matplotlib

I did not succeed to make the characters with alt-code starting from 0 visible in the table (only in the console).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.