hi guys, i need to print the ASCII tabel using only the control staments; the unprintable characters need to be represented by the ASCCII name or a. any ideas that may help?
is the ASCII table define in paython?

The simplest way is to use the dictionary:

# print the control characters of an ASCII table ...

controls_dic = {
1: 'SOH', 2: 'STX', 3: 'ETX', 4: 'EOT', 5: 'ENQ', 6: 'ACK', 7: 'BEL',
8: 'BS', 9: 'HT', 10: 'LF', 11: 'VT', 12: 'FF', 13: 'CR', 14: 'SO',
15: 'SI', 16: 'DLE', 17: 'DC1', 18: 'DC2', 19: 'DC3', 20: 'DC4', 21: 'NAK',
22: 'SYN', 23: 'ETB', 24: 'CAN', 25: 'EM', 26: 'SUB', 27: 'ESC', 28: 'FS',
29: 'GS', 30: 'RS', 31: 'US'}

for key in range(1, 32):
    print key, controls_dic[key]

So I need to print an ASCII table of all characters with values 0 to 127 using char(x). The table needs to be in columns of 16.

How do I do that?

...

>>>for i in range(0,127):
print i


and that will give me a whole print out of all the numbers... but what is an ASCII table and how do I get it in columns of 16? Thanks for your help so far

Here is one example:

# print 0 to 127 in a table of 16 columna

n = 1
for k in range(0, 128):
    if n % 17:
        print "%4d" % k,
    else:
        print
    n += 1

That gives me the numbers in a column of 16, that's good... but how do you get it to display the ASCII table that way?

nevermind.. lol thanks for the link!

This article has been dead for over six months. Start a new discussion instead.