owgitt
owgitt

Reputation: 323

UTF-8 characters usage in python3.4 script is throwing SyntaxError. How to use it?

I am trying execute following lines of code in python3.4:

user ="ŠŒŽ‡†ƒ€‰"
print(user)

But the above user initialization line is resulting in following error:

SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0x8a in position 0: invalid start byte

I want to use the same user in authentication later. How to use UTF-8 characters in python3.4 script ?

Upvotes: 0

Views: 222

Answers (1)

jwodder
jwodder

Reputation: 57520

Your file is not actually saved in UTF-8. Assuming that the syntax error is occurring on the first non-ASCII character (Š), the file is most likely encoded in Windows 1252, which encodes that character as 0x8A. If you wish to continue using this encoding, add this line to the top of your Python file:

# -*- coding: windows-1252 -*-

Upvotes: 4

Related Questions