Python PyCharm:进程已完成,退出代码为 0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49460212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:06:16  来源:igfitidea点击:

PyCharm: Process finished with exit code 0

pythonpycharm

提问by ET44

I am new to PyCharm and I have 'Process finished with exit code 0' instead of getting (683, 11) as a result (please see attachment), could you guys help me out please? Much appreciate it!

我是 PyCharm 的新手,我的结果是“进程已完成,退出代码为 0”,而不是得到 (683, 11)(请参阅附件),你们能帮我吗?非常感谢!

Best regards, ET

最好的问候, ET

enter image description here

在此处输入图片说明

回答by Simon

That is good news! It means that there is no error with your code. You have run it right through and there is nothing wrong with it. Pycharm returns 0 when it has found no errors (plus any output you give it) and returns 1 as well as an error message when it encounters errors.

这是个好消息!这意味着您的代码没有错误。你已经完成了它,它没有任何问题。Pycharm 在没有发现错误时返回 0(加上您提供的任何输出),并在遇到错误时返回 1 和错误消息。

Editors and scripts do not behave like the interactive terminal, when you run a function it does not automatically show the the result. You need to actually tell it to do it yourself.

编辑器和脚本的行为不像交互式终端,当您运行一个函数时,它不会自动显示结果。你需要实际告诉它自己做。

Generally you just printthe results.

通常,您只需打印结果。

If you use print(data.shape)it should return what you expect with the success message Process finished with exit code 0.

如果您使用print(data.shape)它应该返回您期望的成功消息Process finished with exit code 0

回答by Jayhello

exit code 0means you code run with no error.

exit code 0意味着您的代码运行没有错误。

Let's give a error codefor example(clearly in the below image): in below code, the variable lstis an empty list, but we get the 5 member in it(which not exists), so the program throws IndexError, and exit 1which means there is error with the code.

让我们举一个error code例子(在下图中很清楚):在下面的代码中,变量lst是一个空列表,但我们得到了其中的 5 个成员(不存在),所以程序抛出IndexErrorexit 1这意味着有错误编码。

enter image description here

在此处输入图片说明

You can also define exit code for analysis, for example:

您还可以定义用于分析的退出代码,例如:

ERROR_USERNAME, ERROR_PASSWORD, RIGHT_CODE = 683, 11, 0
right_name, right_password = 'xy', 'xy'

name, password = 'xy', 'wrong_password'

if name != right_name:
    exit(ERROR_USERNAME)

if password != right_password:
    exit(ERROR_PASSWORD)

exit(RIGHT_CODE)

enter image description here

在此处输入图片说明

回答by Vaibhav Desai

I would recommend you to read up onexitcodes.

我建议你阅读exit代码。

exit 0means no error.

exit 0意味着没有错误。

exit 1means there is some error in your code.

exit 1意味着您的代码中存在一些错误。

This is not pyCharm or python specific. This is a very common practice in most of the programming languages. Where exit 0 means the successful execution of the program and a non zero exit code indicates an error.

这不是 pyCharm 或 python 特定的。这是大多数编程语言中非常常见的做法。其中 exit 0 表示程序成功执行,非零退出代码表示错误。

回答by Vaibhav Desai

Almost all the program(C++/python/java..) return 0 if it runs successful.That isn't specific to pycharm or python.

如果运行成功,几乎所有程序(C++/python/java..)都返回 0。这不是特定于 pycharm 或 python 的。

In program there is no need to invoke exitfunction explicitly when it runs success it invoke exit(0) by default, invoke exit(not_zero_num)when runs failed.

在程序中exit,运行成功时无需显式调用函数,默认情况下调用 exit(0) ,exit(not_zero_num)运行失败时调用。

You can also invoke exitfunction with different code(num)for analysis.

您还可以调用exit不同的函数code(num)进行分析。

You can also see https://en.wikipedia.org/wiki/Exit_(system_call)for more details.

您还可以查看https://en.wikipedia.org/wiki/Exit_(system_call)了解更多详情。

回答by Mr.Panchamia

please add your code and not the attachment. Also, this means that the compilation was successful (no errors). Pycharm and command prompt (Windows OS), terminal (Ubuntu) don't work the same way. Pycharm is an editor and if you want to print something, you explicitly have to write the print statement:

请添加您的代码而不是附件。此外,这意味着编译成功(没有错误)。Pycharm 和命令提示符(Windows 操作系统)、终端(Ubuntu)的工作方式不同。Pycharm 是一个编辑器,如果你想打印一些东西,你必须明确地编写打印语句:

print(whatever_you_want_to_print)

In your case,

在你的情况下,

print(data.shape)

Hope it helps.

希望能帮助到你。

回答by Jinyu Li

I think there's no problem in your code and you could find your print results (and other outputs) in the tab 5: Debugrather than 4: Run.

我认为您的代码没有问题,您可以在选项卡中找到打印结果(和其他输出)5: Debug而不是4: Run.

回答by TimnDS

I just ran into this, but couldn't even run a simple print('hello world') function.

我刚刚遇到了这个问题,但甚至无法运行一个简单的 print('hello world') 函数。

Turns out Comodo's Firewall was stopping the script from printing. This is a pretty easy fix by deleting Python out of the Settings > Advanced > Script Analysis portion of Comodo.

原来 Comodo 的防火墙阻止了脚本的打印。通过从 Comodo 的设置 > 高级 > 脚本分析部分中删除 Python,这是一个非常简单的修复。

Good Luck

祝你好运

回答by ReubenK

What worked for me when this happened was to go to

当这件事发生时对我有用的是去

Run --> Edit Configurations --> Execution --> check the box Run with Python Console(which was unchecked).

运行 --> 编辑配置 --> 执行 --> 选中该框Run with Python Console(未选中)。