-1
我有一个函数在下面,它查看一个路径,并确定使用多少磁盘空间。main()中的逻辑似乎没有达到else条件 - 为什么
def check_disk_space():
import os
cmdparts = ["echo $(df --output=pcent ", ") | tr -d 'Use% '"]
check_used_disk_space_cmd = cmdparts[0] + "a/path" + cmdparts[1]
os.system(check_used_disk_space_cmd)
def main():
used_disk_space = check_disk_space()
print type(used_disk_space)
if int(used_disk_space) > 80:
print "need more"
else:
print "plennnty!"
print type(used_disk_space)
main()
check_disk_space()
返回85
。
更新:它出现check_disk_space()创建一个NoneType
对象?我得到这个错误: TypeError: int() argument must be a string or a number, not 'NoneType'
因为你没有实际调用的函数,即使你没有它不反正返回任何东西。 –
您需要捕获os.system调用的输出并将其转换为check_disk_space方法中的INT或FLOAT。我会看看[subprocess.Popen](https://docs.python.org/2/library/subprocess.html#popen-constructor)类。 – Kyle
请参阅更新的主要 - 当它真的应该'需要更多' – John