函数输出似乎是12,但作为NoneType对象返回?

时间:2017-09-16 18:58:59

标签: 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 + 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'

如果我打印出type() os.system(check_disk_space_cmd) 'int',我会12,然后是{{1}}的值。

知道这里有什么问题吗?我输了。

谢谢。

1 个答案:

答案 0 :(得分:0)

您的函数需要返回值,因此函数的最后一行应该看起来像

return os.system(check_disk_space_cmd)