python实现的重启关机程序实例
作者:shichen2014 时间:2023-08-09 22:54:20
本文实例讲述了Python实现的重启关机程序的方法,对Python程序设计有一定的参考价值。具体方法如下:
实例代码如下:
#!/usr/bin/python
#coding=utf-8
import time
from os import system
runing = True
while runing:
input = raw_input('关机(s)OR重启(r)?(q退出)')
input = input.lower()
if input == 'q' or input =='quit':
runing = False
print '程序退出'
break
seconds = int(raw_input('请输入暂停时间(单位:秒):'))
time.sleep(seconds)
print '暂停时间:', seconds
runing = False
if input == 's':
print '关机ing'
system('halt')
elif input == 'r':
print '重启ing'
system('reboot')
else:
print '程序错误重新输入'
runing = True
print '程序结束~~~!'
该实例在linux下测试通过,windows的话需要判断执行命令。
标签:python,重启,关机
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python集合比较(交集,并集,差集)方法详解
2023-09-30 22:11:13
python调用webservice接口的实现
2022-10-20 12:54:26
![](https://img.aspxhome.com/file/2023/6/87576_0s.png)
PHP中使用cURL实现Get和Post请求的方法
2023-08-18 13:15:35
Python_LDA实现方法详解
2021-06-29 11:43:18
ZeroClipboard.js使用一个flash复制多个文本框
2024-04-27 15:19:14
Mysql的数据库迁移到另一个机器上的方法详解
2024-01-16 18:33:24
![](https://img.aspxhome.com/file/2023/8/79148_0s.png)
TensorFlow实现卷积神经网络
2022-05-21 02:17:02
![](https://img.aspxhome.com/file/2023/0/87650_0s.jpg)
Python socket实现简单聊天室
2022-06-20 02:13:27
python-opencv 将连续图片写成视频格式的方法
2023-08-25 23:00:06
菜鸟课堂:MySQL权限的详细解答
2009-09-03 11:43:00
利用Python的tkinter模块实现界面化的批量修改文件名
2023-08-30 20:45:15
![](https://img.aspxhome.com/file/2023/6/62286_0s.png)
python实现将list拼接为一个字符串
2022-10-27 05:50:06
echarts柱状图坐标轴内容显示不全的两种解决办法
2023-09-06 03:57:34
![](https://img.aspxhome.com/file/2023/2/56122_0s.png)
简述php环境搭建与配置
2023-11-15 09:08:28
20个Javascript手风琴折叠菜单
2009-10-12 12:09:00
![](https://img.aspxhome.com/file/UploadPic/200910/12/javascript-22-33-23f-88s.jpg)
php中in_array函数用法探究
2023-06-21 21:03:54
适宜做简单搜索的MySQL数据库全文索引
2009-01-04 13:11:00
使用python的pexpect模块,实现远程免密登录的示例
2022-10-19 18:30:22
SQL Server 2008的一些新特点及独到之处
2009-01-15 12:59:00
Python 日志管理模块Loguru的用法小结
2023-02-22 15:45:16
![](https://img.aspxhome.com/file/2023/9/115469_0s.jpg)