python - 从命令提示符运行时程序抛出(文件中以 '\xff' 开头的非 UTF-8 代码)

标签 python

下面是代码:

def add(a,b):
    return a + b
while True:
    try:
        a=float(input('Please enter a number'))
        break
    except:
        print ('Invalid Number, please re-enter')
while True:
    try:
        b=float(input('Please enter a number'))
        break
    except:
        print ('Invalid Number, please re-enter')
print(add(a,b))

最佳答案

我收到一个错误,因为我在 PowerShell 中创建了一个 python 文件,但我正在 VS 代码中编辑它。显然他们使用冲突的编码模式。
我的解决方案:我删除了原始文件并使用 VS 代码创建了一个新文件。
这是详细解释问题所在的链接。
https://docs.microsoft.com/en-us/powershell/scripting/dev-cross-plat/vscode/understanding-file-encoding?view=powershell-7.1

关于python - 从命令提示符运行时程序抛出(文件中以 '\xff' 开头的非 UTF-8 代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52995936/

相关文章:

python - 为什么 Python 字符串连接适用于俄语文本,但 string.format() 不起作用

python - python 3中字典值的总和

python使用lxml和xpath解析html表上的特定数据

python - py2neo 的 WriteBatch 操作失败

python - 即使忽略了 CancelledError,如何取消任务执行?

python - 为什么 'True == not False' 是语法错误?

python - 如何使用 python-sharepoint 库下载文件

python - 从 Python 中的 csv 列中检索每个唯一值首次出现的更有效方法

python - 在 Python3.6+ 中从集合中弹出随机元素的最 Pythonic 方式是什么?

Python错误: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 4