space added before printed line from except block
v.wehren
v.wehren at home.nl
Tue Dec 24 08:21:36 EST 2002
In order to quickly view a "legacy" encoding and its respective Unicode
mapping etc. in Idle, I wrote a simple script printing a table-like
overview, which works fine. What puzzles me however, is that when running it
from the win console or from within the text-based interpreter , an
additional space is placed in front of each printed line coming from the
except UnicodeError block, which is unexpected (that the print statement in
the try block isn't very useful in the console - as it generates an
UnicodeError itself - is, of course, expected and a different matter). Where
does the additional space come from (if it is an additional space)? Anybody?
Merry Xmas!
Vincent Wehren
import sys
def charTable(cpin):
print "|".join(["Decimal".center(10),
"Hex".center(10),
"Current".center(10),
"Uni Hex".center(10),
"Uni Char".center(10)])
print 50 * "-"
for x in range(128, 256):
s = chr(x)
try:
us = unicode(s, cpin)
row = "|".join([str(x).ljust(10),
hex(ord(s)).ljust(10),
s.ljust(10), hex(ord(us)).ljust(10),
us.ljust(10)] )
print row
except UnicodeError:
erow = "|".join([str(x).ljust(10),
hex(ord(s)).ljust(10),
s.ljust(10),
"<undefined>"])
print erow
if __name__ == "__main__":
#test,
charTable("cp866")
More information about the Python-list
mailing list