1

When I'm trying to print all ASCII chars in Python only 127 are getting printed and I'm getting an error with output after 127. I'm unable to understand what does that error mean.

Example:

t = list(range(0, 256))
for x in t:
    print(str(x) + ". " + chr(x))

Error:

Traceback (most recent call last):
  File "D:\Study\Pedia\Python Book\6. Functions\2. Built-in functions\ord_chr.py", line 6, in <module>
    print(str(x) + ". " + str(chr(x)))
  File "C:\Python33\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x80' in position 5: character maps to <undefined>

Note: I can't show you the complete output because I can't copy complete raw output from by sublime output console. Don't know the real reason why it can't get copied.


enter image description here

0

2 Answers 2

1

ASCII includes definitions for 128 characters (0 to 127).

\x80 (128) is not included there.

Sign up to request clarification or add additional context in comments.

9 Comments

@YousufMemon, Which ASCII chart?
@YousufMemon: Where'd you find this chart? Whatever it's showing isn't ASCII.
So this function chr() only encodes Standard ASCII not Extended ASCII
Note that there are about 100 different "extended ASCII" encodings which is why this wholly ambiguous phrase should be entirely avoided. The table which was linked in an earlier comment likely represents CP850, which is used by MS-DOS and is almost completely irrelevant nowadays.
|
1

When I try you code on Windows, Python 2.7, it works without exception. I had to take screenshots as copying the text simply ignored those extended ascii characters.

part 1 part 2 part 3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.