函数输出看起来是12,但是否作为非类型对象返回?

2024-05-18 09:39:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个功能:

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(check_disk_space_cmd)type(),我得到'int',那么12的值。你知道吗

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

谢谢你。你知道吗


Tags: pathimport功能cmdosdefchecktype