Hi I want to know how I can append and then print extended ASCII codes in python. I have the following.
code = chr(247)
li = []
li.append(code)
print li
You are doing nothing wrong.
What you do is to add a string of length 1 to a list.
This string contains a character outside the range of printable characters, and outside of ASCII (which is only 7 bit). That's why its representation looks like '\xf7'
.
If you print it, it will be transformed as good as the system can.
In Python 2, the byte will be just printed. The resulting output may be the division symbol, or any other thing, according to what your system's encoding is.
In Python 3, it is a unicode character and will be processed according to how stdout
is set up. Normally, this indeed should be the division symbol.
In a representation of a list, the __repr__()
of the string is called, leading to what you see.