Python 函数输出似乎是12,但是否作为非类型对象返回?

Python 函数输出似乎是12,但是否作为非类型对象返回?,python,object,typeerror,nonetype,Python,Object,Typeerror,Nonetype,我有一个功能: def check_disk_space(path): import os """ check_disk_space() checks the available space of a specified path """ cmdparts = ["echo $(df --output=pcent ", ") | tr -d 'Use% '"] check_disk_space_cmd = cmdparts[0] + path +

我有一个功能:

def check_disk_space(path):
    import os
    """
    check_disk_space() checks the available space of a specified path
    """
    cmdparts = ["echo $(df --output=pcent ", ") | tr -d 'Use% '"]
    check_disk_space_cmd =  cmdparts[0] + path + cmdparts[1]
    print type(os.system(check_disk_space_cmd))
    return os.system(check_disk_space_cmd)
如果我像这样运行它:

if int(check_disk_space('/path/here')) == 12 :
    print "wooot"
我得到的不是
woot

TypeError: int() argument must be a string or a number, not 'NoneType'
如果我打印出
os.system的
type()

你知道这里怎么了吗?我迷路了


谢谢。

您的函数需要返回值,所以函数的最后一行应该如下所示

return os.system(check_disk_space_cmd)

您的函数不返回任何内容。如果我向其添加
return
,可能还想检查,它仍然输出12。
os.system(check\u disk\u space\u cmd)
返回12,但您的函数不返回。Python不是函数自动返回其计算的最后一个表达式的值的语言之一。您必须显式地
返回
内容。