Question

: My Python program produce a following error message upon execution:
 SyntaxError: Non-ASCII character '\xc4' in file test.py on line 1, but no encoding declared; 

Answer:

Normally the above error message is displayed by python when other characters other then ASCII are used withing your code. The solution is to either remove all non-ASCII characters or include the bellow line into your code to enable UTF-8 encoding:
# - *- coding: utf- 8 - *-
This will allow you to print also non-ASCII character within your code example:
$ cat test.py
# - *- coding: utf- 8 - *-
print "Ľuboš"
$ python test.py
Ľuboš
FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in: