Python SyntaxError: Non-ASCII character '\xe2' in file
You've got a stray byte floating around. You can find it by running
with open("x.py") as fp:
for i, line in enumerate(fp):
if "\xe2" in line:
print i, repr(line)
where you should replace "x.py"
by the name of your program. You'll see the line number and the offending line(s). For example, after inserting that byte arbitrarily, I got:
4 "\xe2 lb = conn.create_load_balancer('my_lb', ['us-east-1a', 'us-east-1b'],[(80, 8080, 'http'), (443, 8443, 'tcp')])\n"
SyntaxError: Non-ASCII character '\xe2' by just copying to another project
The string you have there has a non-ascii character √
which python can't parse. The solution is to replace it with \xe2
which will then expand to √
when the code runs. So the fixed code should look like this:
exp = u"9 \xe2 3 ="
The other solution is to tell python the string you have is actually UTF-8 by prefixing it with a u.
exp = u"9 √ 3 ="
SyntaxError: Non-ASCII character '\xe2' in file but no encoding declared
From the code you've pasted, you can tell where it's going wrong when the syntax coloring gets all weird.
You're using typographical quotes in the statement
aln.append_model(mdl, align_codes=‘5ZEOA', atom_files=‘5ZEO’)
-- that needs to be
aln.append_model(mdl, align_codes='5ZEOA', atom_files='5ZEO')
instead.
Python SyntaxError: Non-ASCII character '\xe2' in file
You have a UTF-8 encoded U+200E LEFT-TO-RIGHT MARK in your docstring:
'\n A company manages owns one of more stores.\xe2\x80\x8e\n '
Either remove that codepoint (and try to use a code editor, not a word processor) from your code, or just put the PEP-263 encoding comment at the top of the file:
# encoding=utf8
Python 3 uses UTF-8 by default, Python 2 defaults to ASCII for source code unless you add that comment.
Python: How to solve SyntaxError: Non-ASCII character?
You file is saved as UTF-16 with BOM (big-endian). I saved your sample code in Notepad++ with that encoding and reproduced the error:
File "test.py", line 1
SyntaxError: Non-ASCII character '\xfe' in file x.py on line 1, but no encoding declared; see http://python.org/dev/peps
/pep-0263/ for details
Make sure your file is saved in the encoding declared. You have to use an encoding compatible with ASCII for the hash bang and encoding lines to be read properly. UTF-16 is not compatible, hence the error message when it read the non-ASCII bytes of the byte order mark (BOM) character.
SyntaxError: Non-ASCII character '\xe2' in file prueba.py on line 3
I guess the problem is you define to use utf8 but don't use a utf8 string. Maybe try to say print u' -------\n│ │\n│ │\n│ │\n││ │\n ------'
Related Topics
How Would I Stop a While Loop After N Amount of Time
Python Argparse Mutual Exclusive Group
Remove Quotes from String in Python
How to Change Index of a for Loop
Pandas Make New Column from String Slice of Another Column
How to Do/Workaround a Conditional Join in Python Pandas
Python: Can Executable Zip Files Include Data Files
Importerror: No Module Named _Ssl
Python: Get the Print Output in an Exec Statement
How to Make a Multidimension Numpy Array with a Varying Row Size
How to Load a Module from Code in a String
"Line Contains Null Byte" in CSV Reader (Python)
Python Webbrowser.Open() to Open Chrome Browser
Calculate Average of Every X Rows in a Table and Create New Table
How Include Static Files to Setuptools - Python Package
Why Do Some Functions Have Underscores "_" Before and After the Function Name