I'm trying to write a short script (for a tutorial) to show which of the first 128 ASCII characters are printable, recognizable characters.
The following script using `is in string.printable' partially works, but is still triggering off of things like line feeds, etc.
Is there one or two more lines I can add to trap and replace these control characters with spaces so that the table looks nice and shows printable characters?
Written out longhand for noob-readability:
import string
lines = []
for i in range(8):
line = []
for j in range(16):
k = i + j *16
thing = chr(k)
if thing not in string.printable:
thing = ' '
line.append(thing)
lines.append(line)
for line in lines:
print "".join(line)
IDLE:
Copy/paste into SE including four spaces:
0@P`p
!1AQaq
"2BRbr
#3CScs
$4DTdt
%5EUeu
&6FVfv
'7GWgw
(8HXhx
)9IYiy
*:JZjz
+;K[k{
,<L\l|
-=M]m} .>N^n~ /?O_o