close

[Solved] SyntaxError of Non-ASCII character

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error SyntaxError of Non-ASCII character in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How SyntaxError of Non-ASCII character5 Error Occurs?

Today I get the following error SyntaxError of Non-ASCII character in python.

How To Solve SyntaxError of Non-ASCII character Error ?

  1. How To Solve SyntaxError of Non-ASCII character Error ?

    To Solve SyntaxError of Non-ASCII character Error Adding the following two lines at the top of my .py script worked for me (first line was necessary):

  2. SyntaxError of Non-ASCII character

    To Solve SyntaxError of Non-ASCII character Error Adding the following two lines at the top of my .py script worked for me (first line was necessary):

Solution 1

Adding the following two lines at the top of my .py script worked for me (first line was necessary):

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

Solution 2

First add the # -*- coding: utf-8 -*- line to the beginning of the file and then use u'foo' for all your non-ASCII unicode data:

def NewFunction():
    return u'£'

or use the magic available since Python 2.6 to make it automatic:

from __future__ import unicode_literals

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read