python实现的重启关机程序实例

yipeiwu_com6年前Python基础

本文实例讲述了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 内置函数complex详解

英文文档: class complex([real[, imag]]) Return a complex number with the value real + imag*1j or...

Python常用模块介绍

python除了关键字(keywords)和内置的类型和函数(builtins),更多的功能是通过libraries(即modules)来提供的。 常用的libraries(module...

详解Python3之数据指纹MD5校验与对比

MD5消息摘要算法(英语:MD5 Message-Digest Algorithm),一种被广泛使用的密码散列函数,可以产生出一个128位(16字节)的散列值(hash value),用...

Python读写Excel文件的实例

Python读写Excel文件的实例

最近由于经常要用到Excel,需要根据Excel表格中的内容对一些apk进行处理,手动处理很麻烦,于是决定写脚本来处理。首先贴出网上找来的读写Excel的脚本。 1.读取Excel(需要...

基于Python socket的端口扫描程序实例代码

本文研究的主要是Python的端口扫描程序,具体实例代码如下。 先来看看第一个端口扫描程序代码,获取本机的IP和端口号: import socket def get_my_ip...