python,開發錯誤一:SyntaxError: Non-UTF-8 code starting with '\xca' in file

yy418408247發表於2021-11-11
錯誤截圖:
具體報錯資訊:
C:\Users\Administrator.DESKTOP-IFL2F1P\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Administrator.DESKTOP-IFL2F1P/PycharmProjects/pythonProject/venv/IfElse.py
SyntaxError: Non-UTF-8 code starting with '\xca' in file C:\Users\Administrator.DESKTOP-IFL2F1P\PycharmProjects\pythonProject\venv\IfElse.py on line 5, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details
Process finished with exit code 1
處理方案:
案例一:
原始碼:
num=5
if num % 2 ==0 :
    print(str(num)+"是一個偶數")
else :
    print(str(num)+"是一個奇數")
在程式碼開頭加上:
# -*- coding: gb2312 -*-
更改後:
# -*- coding: gb2312 -*-
num=5
if num % 2 ==0 :
    print(str(num)+"是一個偶數")
else :
    print(str(num)+"是一個奇數")

進行執行

C:\Users\Administrator.DESKTOP-IFL2F1P\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Administrator.DESKTOP-IFL2F1P/PycharmProjects/pythonProject/venv/IfElse.py

5是一個奇數

Process finished with exit code 0


遊戲是我的全部圖景,我將演繹所有的遊戲角色,我是每個活著角色的傳奇。   --清

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29494175/viewspace-2841709/,如需轉載,請註明出處,否則將追究法律責任。

相關文章