gpt4 book ai didi

python - 一直试图让用户输入分钟,以便 Python 可以将其转换为命令行的秒

转载 作者:行者123 更新时间:2023-12-01 05:05:38 25 4
gpt4 key购买 nike

minute = 60
shutdown = ("Shutdown")
log_off = ("Log Off")
restart = ("Restart")
import time
time.sleep(1)
option = input("What would you like to do today?\n Shutdown \n Restart \n Log Off\n")
if option == shutdown:
time.sleep(1)
print("You have selected to", shutdown)
time.sleep(0.5)
time_shutdown = input("How long do you want until the machine shuts down?(in minutes)")
number = int(time_shutdown)
#So at this point I want the minutes converted to seconds
minutes = number * minute
#So this should then convert the minutes into seconds
import subprocess
subprocess.call(["shutdown.exe", "-f", "-s", "-t", minutes])
print("Your command has been processed...")
time.sleep(1.5)
number = int(time_shutdown)
minutes = number / minute
print("Your machine will close down in", minutes,"minutes.")


Traceback (most recent call last):
File "C:\Python34\test.py", line 23, in <module>
subprocess.call(["shutdown.exe", "-f", "-s", "-t", minutes])
File "C:\Python34\lib\subprocess.py", line 537, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Python34\lib\subprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1085, in _execute_child
args = list2cmdline(args)
File "C:\Python34\lib\subprocess.py", line 663, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'int' is not iterable

我迫切需要一些关于如何使其发挥作用的建议,因为我一整天都在试图弄清楚。我希望我没有错过一些我应该放在那里的愚蠢的东西。

有人可以帮我吗?

最佳答案

您的错误似乎是由 subprocess.call 尝试将您的 分钟 参数解释为字符串引起的。尝试改变

subprocess.call(["shutdown.exe", "-f", "-s", "-t", minutes])

subprocess.call(["shutdown.exe", "-f", "-s", "-t", str(minutes)])

关于python - 一直试图让用户输入分钟,以便 Python 可以将其转换为命令行的秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25099973/

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