I am trying to run vba_extract.py in Visual Studio by IronPython. The compilation returns an error:
An unhandled exception of type 'Microsoft.Scripting.SyntaxErrorException' occurred in IronPython.dll
Additional information: Non-ASCII character '\xb7' in file ../../python/vba_extract.py ../../../tests/test.xlsm on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
I searched this issue, and added encoding in Line 2 of vba_extract.py:
#!python
# -*- coding: utf-8 -*-
But it still does not work.
Additionally, I tried the following two lines, which returned the same error:
engine.ExecuteFile(#"../../python/irrelevant.py ../../../tests/test.xlsm");
engine.ExecuteFile(#"../../tests/test.xlsm");
So I guess the problem is from the encoding of test.xlsm.
Could anyone help?
Related
é character belongs to utf-8 as shown in:
https://www.utf8-chartable.de/unicode-utf8-table.pl
As official documentation (https://www.python.org/dev/peps/pep-0263/)
says:
'In Python 2.1, Unicode literals can only be written using the Latin-1 based encoding "unicode-escape"....'
I use Python 2.7.13
so in my code (as told in https://www.python.org/dev/peps/pep-0263/), I have tried successively (after #!/usr/bin/python)
# coding=utf-8
# -*- coding: utf-8 -*-
the last one also appears in the post solution Correct way to define Python source code encoding
but it still does not work:
SyntaxError: Non-ASCII character '\xc3' in file ./<file_name>.py on line 160, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Any ideas folks ?? thanx.
I wrote a script to extract signals from the MIT-BIH dataset using the wfdb python library. The script was working fine when I was running it on windows but I recently shifted to Mac. After installing all the dependencies I got an error when I tried to import processing from the wfdb library. This is the error I get:
SyntaxError: Non-ASCII character '\xe2' in file /usr/local/lib/python2.7/site-packages/scipy/stats/_continuous_distns.py on line 3346, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
import wfdb works fine but there seems to be a problem when I do from wfdb import processing. Is there any way to solve this issue?
Please add following line at the top of the code.
# -*- coding: utf-8 -*-
Also, avoid using non-ascii quotations.
This error is caused due to copying and pasting code from web which causes stray byte floating. You can find it by running.
with open('my_script.py', 'r') as ms:
for i, line in enumerate(ms):
if '\xe2' in line:
print(i, repr(line))
And the line and its index value will be printed where there is '\xe2':
4, "\xe2 word=string.printable(random.randint[0,61]) # Gets the random word"
Note: You should replace my_script.py with your respective .py file.
This was due to a scipy bug which has been fixed.
This is my code:
mylist=['尺','选择']
[x.encode('utf-8') for x in mylist]
beofore i could even get to the second line of my file, the script returns an error:
SyntaxError: Non-ASCII character '\xe5' in file but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
how do i solve this?
You need to set source code encoding to UTF-8 for this. As per PEP-0263 , Try setting the below line at the top of the script
# -*- coding: utf-8 -*-
The different styles possible for specifying source code encodings are given in the PEP linked above.
I'm trying learning to use encoding declarations in source files reading PEP 263 and I'm experimenting on my own but I got some troubles.
Here's my file cod.py:
# -*- coding: utf-16 -*-
print('ciao')
and I saved it using UTF-16 encoding; now:
antox#antox-pc ~/Scrivania $ python3 cod.py
File "cod.py", line 1
SyntaxError: Non-UTF-8 code starting with '\xff' in file cod.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
So I don't understand where I'm getting wrong.
P.S. I'm using gedit 2.30.4
UTF-16 is not accepted as encoding for Python source code. From PEP 263 (section Concepts, item 1):
Any encoding which allows processing the first two lines in the
way indicated above is allowed as source code encoding, this
includes ASCII compatible encodings as well as certain
multi-byte encodings such as Shift_JIS. It does not include
encodings which use two or more bytes for all characters like
e.g. UTF-16. The reason for this is to keep the encoding
detection algorithm in the tokenizer simple.
So the error you're getting is expected: you can use a different encoding (other than the default UTF-8) as long as it can be detected by Python.
Im starting with python and when i use the interpreter and run this code:
>>>peliculas = ["movie1", "movie2", "movie3", "movie4"]
>>>print(peliculas[1])
when i use Pycharm IDE it doesnt compile:
peliculas = ["movie1", "movie2", "movie3", "movie4"]
print(peliculas[1])
This is the output:
File "/Users/user/PycharmProjects/untitled/Prueba2.py", line 1
SyntaxError: Non-ASCII character '\xc3' in file /Users/user/PycharmProjects/untitled/Prueba2.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
What´s wrong with python?.. do i installed it correctly?
Just add these two lines at to top of python code.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
It's a file encoding problem. Try adding this at the beginning of the file:
#coding=utf-8
In PyCharm you can specify file encoding via the File | File encoding menu, or the file encoding item on the status bar. See this help article