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?

Recommended Answers

All 12 Replies

>>> chr(45)
'-'
>>> ord('a')
97
>>>

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]

Good point. Sorry for the incomplete solution!

Jeff

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?

Well, can you get the table to print out without the formatting requirements?

Jeff

...

>>>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

can i do this?

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

??

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

There is a slight flaw in ZZucker's post, but the OP should have reason this out for themselves.

commented: good eyes +3

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!

Thank You a mother load! That really helped!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.