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

Python消息:进程已完成,退出代码为0,python,Python,我收到一条Python消息,上面说 进程已完成,退出代码为0 我没有看到任何错误代码。我确保数据源的路径是正确的。我签入设置并显示pandas和matplotlib库已安装 数据源是模拟IP地址列表,代码假定按降序打印IP地址列表。如前所述,我只得到“进程结束,退出代码为0” 非常感谢您的帮助 import pandas as pd import matplotlib.pyplot as plt # Function to print the results def printResults

我收到一条Python消息,上面说

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

我没有看到任何错误代码。我确保数据源的路径是正确的。我签入设置并显示pandas和matplotlib库已安装

数据源是模拟IP地址列表,代码假定按降序打印IP地址列表。如前所述,我只得到“进程结束,退出代码为0”

非常感谢您的帮助

import pandas as pd
import matplotlib.pyplot as plt


# Function to print the results
def printResults(message, value):
    print("\n\n")
    print(message)
    print()
    print(value)

    # set the file path
    # Note: you may have to change the path to file
    data = '/Users/Student1/Documents/Class_Dataset1.csv'

    # Read the file into the data frame
    nd = pd.read_csv(data, sep=',', decimal='.', header=0)

    # Print the source IP frequencies
    printResults("Source IP", nd['Source'].value_counts())

    # Print the destination IP frequencies
    printResults("Destination IP", nd['Destination'].value_counts())

    # Print the Protocol Frequencies
    printResults("Protocol", nd['Protocol'].value_counts())

由于您从不调用函数,因此代码永远不会运行,您只能使用退出代码0完成
过程(这意味着您的Python代码成功运行)。

请将您的代码更正为

import pandas as pd
import matplotlib.pyplot as plt


# Function to print the results
def printResults(message, value):
    print("\n\n")
    print(message)
    print()
    print(value)


# set the file path
# Note: you may have to change the path to file
data = '/Users/Student1/Documents/Class_Dataset1.csv'

# Read the file into the data frame
nd = pd.read_csv(data, sep=',', decimal='.', header=0)

# Print the source IP frequencies
printResults("Source IP", nd['Source'].value_counts())

# Print the destination IP frequencies
printResults("Destination IP", nd['Destination'].value_counts())

# Print the Protocol Frequencies
printResults("Protocol", nd['Protocol'].value_counts())

解释如下:

我在代码中唯一更改的是行的缩进

在您的代码中,所有命令都是函数定义的一部分,您从未调用过,因此除了消息外,没有打印任何内容

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

(每个进程都以一些退出代码结束,Python解释器中的退出代码
0
(几乎在所有程序中都是如此)意味着一切正常


事实上,如果您实际上做了其他事情,但是您的代码在语法上仍然正确,没有任何运行时错误,那么Python没有机会透露您想要做什么。)

错误代码0表示程序成功结束,没有任何错误。如果它是除0以外的任何其他错误号,那么它将是一个错误

此外,我认为您的代码需要如下所示的正确缩进,以便您可以获得所需的输出,而不是什么都没有:

import pandas as pd
import matplotlib.pyplot as plt


# Function to print the results
def printResults(message, value):
    print("\n\n")
    print(message)
    print()
    print(value)

# set the file path
# Note: you may have to change the path to file
data = '/Users/Student1/Documents/Class_Dataset1.csv'

# Read the file into the data frame
nd = pd.read_csv(data, sep=',', decimal='.', header=0)

# Print the source IP frequencies
printResults("Source IP", nd['Source'].value_counts())

# Print the destination IP frequencies
printResults("Destination IP", nd['Destination'].value_counts())

# Print the Protocol Frequencies
printResults("Protocol", nd['Protocol'].value_counts())

你从不调用你的函数,所以它永远不会被执行。这个消息来自于进程执行的任何东西,它意味着进程没有返回错误代码。在您的例子中,函数从未被调用,因此python返回0。一般来说,这取决于过程。有些会大量爆炸,但仍然返回0。其他人会很好地工作并返回非零,因为非零对该程序有不同的含义。稍后我将研究为什么不适当地缩进代码行,特别是在函数定义下面。我猜Python仍然假设我再次定义了“Def printfresults函数”,谢谢您的帮助。真诚的霍顿库尔德。@霍顿库尔德,不客气。请阅读我认为问题不在于OP得到了那个输出,而是他们得到了所有的输出。换句话说,没有有用的结果。@paxdiablo Ok。谢谢你让我知道你的答案似乎和另一个几乎一样…:-)似乎是一份大约20分钟前发布的副本。是的,似乎是这样,但事实上我没有复制:)我写了我自己的答案,但我自己的答案基本上是另一个:)这对我来说很有趣:)@Saeed,没关系,这(也发生在我身上)。:-)@我希望OP能接受我最好的答案,因为我写得更少:)