重启计算机的Python脚本
众所周知, Python是一种流行的脚本语言,因为它具有多种功能。在本文中,我们将编写一个Python脚本来重新启动计算机。让我们从如何使用Python重启系统开始。
Note: For this to work, you have to import os library
in the ide. If you don’t have it, then ‘pip install os
‘ through the Command Prompt.
Causion: Please ensure that you save and close all the program before running this code on the IDLE, as the below program will immediately restart your computer.
下面是Python的实现——
import os
restart = input("Do you wish to restart your computer ? (yes / no): ")
if restart == 'no':
exit()
else:
os.system("shutdown /r /t 1")
输出:
这是Python程序,它将要求用户重新启动计算机,提供是或否的选项。此外,当您键入 yes 并按 ENTER 键时,系统将立即重新启动。