我是靠谱客的博主 柔弱冰淇淋,这篇文章主要介绍python实现的重启关机程序实例,现在分享给大家,希望可以做个参考。

本文实例讲述了Python实现的重启关机程序的方法,对Python程序设计有一定的参考价值。具体方法如下:

实例代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/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实现的重启关机程序实例的全部内容,更多相关python实现内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(152)

评论列表共有 0 条评论

立即
投稿
返回
顶部