Chinaunix首页 | 论坛 | 博客
  • 博客访问: 482211
  • 博文数量: 135
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 1441
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-05 20:39
文章分类
文章存档

2012年(2)

2011年(130)

2009年(2)

2008年(1)

我的朋友

分类:

2011-08-26 12:17:53

#coding=utf8
import time
import sys
import os
def restart_program():
    """Restarts the current program.
    Note: this function does not return. Any cleanup action (like
    saving data) must be done before calling this function."""
    python = sys.executable
    os.execl(python, python, * sys.argv)
if __name__ == "__main__":
    print 'start...'
    answer = raw_input("Do you want to restart this program ? ")
    if answer.strip() in "y Y yes Yes YES".split():
        restart_program()
    print "3秒后,程序将结束..."
    time.sleep(3)
 
 
运行结果如下:
[root@localhost sinatpy2.x]# python restart_self.py
start...
Do you want to restart this program ? y
start...
Do you want to restart this program ? y
start...
Do you want to restart this program ? y
start...
Do you want to restart this program ? y
start...
Do you want to restart this program ? yes
start...
Do you want to restart this program ? n
3秒后,程序将结束...
[root@localhost sinatpy2.x]#

阅读(2073) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~