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
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
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.
python
unicode
encode
python-3.3
trackback
|
this question
edited Jan 14 '14 at 15:11 asked Jan 14 '14 at 14:46
Yousuf Memon 1,739 7 24 49 @Wooble Edited. –
Yousuf Memon Jan 14 '14 at 14:52
|
2 Answers
2
---Accepted---Accepted---Accepted---
ASCII includes definitions for 128 characters (0 to 127).
\x80 (128) is not included there.ill it puts up a error like this, I use print(data1) and the html is printed properlyand I am using python 3.5.0 import reimport urllib.requestcity = input("city name") url = "http://www.weather-forecast.com/locations/"+city+"/forecas
|
this answer answered Jan 14 '14 at 14:50
falsetru 189k 24 253 293 But the ASCII chart has 256 chars. Maybe I'm wrong. –
Yousuf Memon Jan 14 '14 at 14:54 @YousufMemon, Which ASCII chart? –
falsetru Jan 14 '14 at 14:56 @YousufMemon: Where'd you find this chart? Whatever it's showing isn't ASCII. –
geoffspear Jan 14 '14 at 14:56 It's extended ASCII:
theasciicode.com.ar/ascii-control-characters/… –
Thorsten Kranz Jan 14 '14 at 14:57 1 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. –
ntoskrnl Jan 14 '14 at 17:42
|
show more comments
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.
|
this answer answered Jan 14 '14 at 15:03
Thorsten Kranz 7,700 17 37
|
tried several of the answers in many a thread but none of them seemed to work properly for my problem. import jsondef parse(fn): results = [] with open(fn) as f: json_obj = json.loads(open(fn).read()) for r in json