Skip to main content
added 314 characters in body
Source Link
Karl Knechtel
  • 61.3k
  • 14
  • 131
  • 193

I tried this code in Python 2:

def NewFunction():
    return '£'

But I get an error message that says:

SyntaxError: Non-ASCII character '\xa3' in file '...' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Similarly, in Python 3, if I write the same code and save it with Latin-1 encoding, I get:

SyntaxError: Non-UTF-8 code starting with '\xa3' in file ... on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

How can I use a pound sign in string literals in my code?


See also: Correct way to define Python source code encoding for details about whether an encoding declaration is needed and how it should be written. Please use that question to close duplicates asking about how to write the declaration, and this one for questions asking about resolving the error.

I tried this code in Python 2:

def NewFunction():
    return '£'

But I get an error message that says:

SyntaxError: Non-ASCII character '\xa3' in file '...' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Similarly, in Python 3, if I write the same code and save it with Latin-1 encoding, I get:

SyntaxError: Non-UTF-8 code starting with '\xa3' in file ... on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

How can I use a pound sign in string literals in my code?

I tried this code in Python 2:

def NewFunction():
    return '£'

But I get an error message that says:

SyntaxError: Non-ASCII character '\xa3' in file '...' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Similarly, in Python 3, if I write the same code and save it with Latin-1 encoding, I get:

SyntaxError: Non-UTF-8 code starting with '\xa3' in file ... on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

How can I use a pound sign in string literals in my code?


See also: Correct way to define Python source code encoding for details about whether an encoding declaration is needed and how it should be written. Please use that question to close duplicates asking about how to write the declaration, and this one for questions asking about resolving the error.

improve title SEO (the issue is version-agnostic); rm noise and avoid nonsensical use of terminology; show 3.x example
Source Link
Karl Knechtel
  • 61.3k
  • 14
  • 131
  • 193

SyntaxError "SyntaxError: Non-ASCII character '\xa3'..." or "SyntaxError: Non-UTF-8 code starting with ..." trying to use non-ASCII text in file when function returns '£'a Python script

Say I have a functiontried this code in Python 2:

def NewFunction():
    return '£'

But I want to print some stuff with a pound sign in front of it and it printsget an error when I try to run this program, this error message is displayedthat says:

SyntaxError: Non-ASCII character '\xa3' in file 'blah' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details
SyntaxError: Non-ASCII character '\xa3' in file '...' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Can anyone inform me howSimilarly, in Python 3, if I write the same code and save it with Latin-1 encoding, I get:

SyntaxError: Non-UTF-8 code starting with '\xa3' in file ... on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

How can includeI use a pound sign in string literals in my return functioncode? I'm basically using it in a class and it's within the '__str__' part that the pound sign is included.

SyntaxError: Non-ASCII character '\xa3' in file when function returns '£'

Say I have a function:

def NewFunction():
    return '£'

I want to print some stuff with a pound sign in front of it and it prints an error when I try to run this program, this error message is displayed:

SyntaxError: Non-ASCII character '\xa3' in file 'blah' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Can anyone inform me how I can include a pound sign in my return function? I'm basically using it in a class and it's within the '__str__' part that the pound sign is included.

"SyntaxError: Non-ASCII character ..." or "SyntaxError: Non-UTF-8 code starting with ..." trying to use non-ASCII text in a Python script

I tried this code in Python 2:

def NewFunction():
    return '£'

But I get an error message that says:

SyntaxError: Non-ASCII character '\xa3' in file '...' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Similarly, in Python 3, if I write the same code and save it with Latin-1 encoding, I get:

SyntaxError: Non-UTF-8 code starting with '\xa3' in file ... on line 2, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

How can I use a pound sign in string literals in my code?

Post Reopened by tripleee, PM 2Ring python
Post Closed as "Duplicate" by tripleee, davidism python
Formatting, grammar, tags
Source Link
hichris123
  • 10.3k
  • 15
  • 58
  • 70

Hi I'm trying understand why I'm getting this error.

Say I have a function:

def NewFunction():
    return '£'

I want to print some stuff with a pound sign in front of it and it prints an error when I try to run this program, this error message is displayed:

SyntaxError: Non-ASCII character '\xa3' in file 'blah' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Can anyone inform me how I can include a pound sign in my return function.? I'm basically using it in a class and it's within the 'str''__str__' part that the pound sign is included.

Regards

SNIFFY

Hi I'm trying understand why I'm getting this error.

Say I have a function:

def NewFunction():
    return '£'

I want to print some stuff with a pound sign in front of it and it prints an error when I try to run this program, this error message is displayed:

SyntaxError: Non-ASCII character '\xa3' in file 'blah' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Can anyone inform me how I can include a pound sign in my return function. I'm basically using it in a class and it's within the 'str' part that the pound sign is included.

Regards

SNIFFY

Say I have a function:

def NewFunction():
    return '£'

I want to print some stuff with a pound sign in front of it and it prints an error when I try to run this program, this error message is displayed:

SyntaxError: Non-ASCII character '\xa3' in file 'blah' but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details

Can anyone inform me how I can include a pound sign in my return function? I'm basically using it in a class and it's within the '__str__' part that the pound sign is included.

Source Link
SNIFFER_dog
  • 3.3k
  • 2
  • 16
  • 4
Loading