0

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

4
  • 1
    the complete stacktrace would be helpfull here. Commented Jun 10, 2013 at 10:54
  • Pic uploaded to main question Commented 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. Commented 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.) Commented Jun 10, 2013 at 11:56

2 Answers 2

1

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.

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

1 Comment

Open the file in Notepad++ again and re-save it as a UTF-8 file. Then you'll be able to use all kinds of weird symbols!
0

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')) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.