3
I made a very simple program, this way, in the notebook, and saved how Somador.py
:
a = 1
b = 1
soma = a + b
print("A soma dos números é", soma)
After that I tried to run the program by cmd
and gave that message:
SyntaxError: Non-UTF-8 code starting with '\xfa' in file C:\Users\Paulo\Desktop\
Somador.py on line 6, but no encoding declared; see http://python.org/dev/peps/p
ep-0263/ for details
I thought the encoding comment at the beginning of the file was just to inform other programmers about which encoding it. In this case, the Python interpreter reads this line and auto-configures to read the rest of the code in the specified encoding, is that it? If so, should the declaration be in the first line or in any part of the code? And is there any tool to put this statement in all the files
.py
of a project, so as not to have to put one on one?– JeanExtreme002
@Jeanextreme002 According to PEP 263, It has to be in the first or second line of the file, and I don’t know the implementation details, but I imagine it "auto configure" itself. As for tools, I never used but I would guess that there must be :-)
– hkotsubo