Python and VS Code issues



VS Code终端不会输出我的Python代码。

我一直得到这个:

PS C:UsersdanieOneDriveDocumentsExercise FilesCh2> cd 'c:UsersdanieOneDriveDocumentsExercise FilesCh2'; ${env:PYTHONIOENCODING}='UTF-8'; ${env:PYTHONUNBUFFERED}='1'; & 'C:/Python/Python37/Python.exe' 'c:Usersdanie.vscodeextensionsms-python.python-2019.5.18875pythonFilesptvsd_launcher.py' '--default' '--client' '--host' 'localhost' '--port' '57829' 'c:UsersdanieOneDriveDocumentsExercise FilesCh2helloworld_start.py'

我已经设置了启动。JSON 文件如下所示

"version": "0.2.0",
"configurations": [
    {
        "name": "Python",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config:python.pythonPath}",
        "program": "${file}",
        "cwd": "",
        "env": {},
        "envFile": "${workspaceRoot}/.env",     
    }
]

这是我的代码:

def main():
    print("hello world")
    if __name__ == "__main__":
        main()

我只想打印出"hello world",但似乎我在设置中缺少一些东西。

调用 main 函数的最后两行是缩进的。这意味着它们是主要功能的一部分。

通过删除缩进,这两行将在您运行文件并按预期调用 main 函数时执行。看到这里

def main():
    print("hello world")
if __name__ == "__main__":
    main()

最新更新