gpt4 book ai didi

python - 我的代码有一个 if-else 条件,但我认为代码没有检查 if 条件,而是直接进入 else 条件

转载 作者:太空宇宙 更新时间:2023-11-04 11:09:52 26 4
gpt4 key购买 nike

我有这个代码来改变文件系统的大小。问题是,即使满足 if 条件,它也不会进入 if 条件,而我根本没有检查 if 条件。它直接进入 else 条件。

运行代码后的结果

post-install-ray.py chpasswd

chpasswd root:Deepsky24

df -g | grep -w / | awk '{ print $3 }' 0.89

df -g | grep -w /usr | awk '{print $3 }' 5.81

chfs -a size=+4G / Filesystem size changed to 10354688

代码:

import subprocess
import sys
import pexpect
from pexpect import pxssh
import logging

password = "Deepsky24"
hostname = "host"
username = "root"

def change_filesystem():
child = pxssh.pxssh()
child.login(hostname, username, password)
child.sendline("df -g | grep -w / | awk '{ print $3 }'")
child.prompt()
output1 = child.before
print output1
child.sendline("df -g | grep -w /usr | awk '{print $3 }'")
child.prompt()
output2 = child.before
print output2
if (output1 <= 1 and output2 >= 4):

child.sendline('chfs -a size=-3G /usr')
child.prompt()
print(child.before)
child.sendline('chfs -a size=+3G /')
child.prompt()
print(child.before)

else:

child.sendline('chfs -a size=+4G /')
child.prompt()
print(child.before)

if __name__== "__main__":

change_filesystem()

最佳答案

您的两个输出仍然是字符串,您需要将它们转换为 float

output1 = float(child.before)
output2 = float(child.before)

关于python - 我的代码有一个 if-else 条件,但我认为代码没有检查 if 条件,而是直接进入 else 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58540663/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com