[Tutor] help - SyntaxError: Non-UTF-8 code using python 3

Lily Tran lilytran at adobe.com
Thu Aug 9 07:12:41 CEST 2012


Thanks.  I found the problem character and was able to resolve it.

Lily

On 8/8/12 10:10 PM, "Dave Angel" <d at davea.name> wrote:

>On 08/08/2012 11:26 PM, Lily Tran wrote:
>> Hello;
>>
>>
>> I am getting the following error when I try to run this python program
>>in eclipse.  I am running python 3:
>>
>>
>>  File "/Users/lilytran/Desktop/python/Ex_Files_Python_3_EssT/Exercise
>>Files/class_beginner_python/hw3_2_lab6.py", line 30
>>
>> SyntaxError: Non-UTF-8 code starting with '\xd0' in file  on line 30,
>>but no encoding declared; see http://python.org/dev/peps/pep-0263/ for
>>details
>>
>> ============================================================
>>
>>
>> Can you please tell me what I am doing wrong and how do I fix this
>>error?  Below is my program.  Thanks ­Lily
>>
>> ====================================================
>>
>>
>> import random
>>
>>
>>
>> def MagicEightBallEmulator():
>>
>> <SNIP>
>>         what = random.choice(answers)
>>
>>     return print(what)
>>
>>
>> def RunEmulator():
>>
>>     while True:
>>
>>         print ('Welcome to Magic 8 Ball!')
>>
>>         print ('Please ask your question!')
>>
>>         question = input()
>>
>>         if question == 'quit':
>>
>>             break
>>
>>         MagicEightBallEmulator()
>>
>>
>>
>> RunEmulator()
>>
>>
>
>Sending us the source without adding a comment to line #30 seems a bit
>presumptuous. Double spacing by sending it as a non-text message makes
>it worse.
>
>The error message itself seems pretty clear. You have a non-UTF8
>sequence in a source file implicitly declared as being UTF8.
>
>Simplest solution? Don't use non-ASCII characters. You are probably
>entering some character (perhaps 0x000000D0) encoded in some other form,
>and the compiler cannot decode it because it's not in UTF-8. How might
>you have gotten an non-ASCII character? It might be on your keyboard,
>like an o with an umlaut. Or you might have pasted it from a word
>processing document or a pdf file, like a "smart quote."
>
>Better solution? Use a text editor that understands encodings, and set
>it to always use UTF-8.
>
>Another solution? Figure out what encoding your editor is stuck in, and
>declare that in your python file, as the second line.
>
>Final solutions? Use a hex viewer to search the file for that D0
>mentioned, and figure out just where in your source it is. There's no
>reason to assume we could even see it here, since your message is
>encoded in Windows-1252.
>
>-- 
>
>DaveA
>



More information about the Tutor mailing list