I have written a Python 3.3 program in Ubuntu that works fine. However, when I run it in windows, I get Unicode encode errors. The line it complains about is:
if minor:
print (textwrap.fill('{}: {}'.format(minor,MINOR[minor])),"\n")
but I cannot see why it would work under Ubuntu and not Windows. Which character won't windows like? I can't see anything wrong with it.
error pic
-
1the complete stacktrace would be helpfull here.pypat– pypat2013年06月10日 10:54:15 +00:00Commented Jun 10, 2013 at 10:54
-
Pic uploaded to main questionSimkill– Simkill2013年06月10日 10:56:50 +00:00Commented Jun 10, 2013 at 10:56
-
The problem is probably the encoding of the terminal. In linux it is usually utf-8, on windows it's probably latin-1 or cp1252.Bakuriu– Bakuriu2013年06月10日 11:12:03 +00:00Commented Jun 10, 2013 at 11:12
-
What do you expect this function to print? It tries to print a string containing a character that's invalid in UTF-8 and latin-1 (but valid in cp-1252.)kqr– kqr2013年06月10日 11:56:51 +00:00Commented Jun 10, 2013 at 11:56
2 Answers 2
As it turned out, the problem was in the csv file that was loaded into the 'minor' constant (in this case, dictionary). The problem was where I had copied the txt from was using some weird version of the apostrophe character instead of what it would usually use, so I ran a replace through notepad++ and fixed it.
1 Comment
I was having the same problem i solved it in the following way : First decode the string (say string 1) then perform further operations :
string_decoded= (string1.decode('latin_1'))