让Python脚本暂停执行的几种方法(小结)

yipeiwu_com6年前Python基础

1.time.sleep(secs)

参考文档原文:

Suspend execution for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time. The actual suspension time may be less than that requested because any caught signal will terminate the sleep() following execution of that signal's catching routine. Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system.

大意:

让程序执行暂停指定的秒数,参数可以是浮点型以指定精确的时间,但是程序真正暂停的时间可能长于请求的时间也可能短于暂停的时间。

2. raw_input( )

通过等待输入来让程序暂停

3. os.system("pause")

通过执行操作系统的命令来让程序暂停,该函数是通过实现标准C函数system( )来实现的。

Python2.4新加入了subprocess模块,而且官方建议使用改模块替换os.system所以,也可以这样写:

subprocess.call("pause",shell=True)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python使用QQ邮箱发送Email的方法实例

Python使用QQ邮箱发送Email的方法实例

前言 其实Python使用QQ邮箱发送Email代码很简单,短短几行代码就可以实现这个功能。 使用到的模块有smtplib和email这个两个模块,关于这两个模块的方法就不多说了。不了...

1分钟快速生成用于网页内容提取的xslt

1分钟快速生成用于网页内容提取的xslt

1分钟快速生成用于网页内容提取的xslt,具体内容如下 1、项目背景 在《Python即时网络爬虫项目说明》一文我们说过要做一个通用的网络爬虫,而且能节省程序员大半的时间,而焦点问题就是...

django 连接数据库 sqlite的例子

Aphorism the fight is worth it. django models 连接 sqlite 数据库 django 版本为 1.11.7 在 blog 项目下创建一个...

解决python3中自定义wsgi函数,make_server函数报错的问题

#coding:utf-8 from wsgiref.simple_server import make_server def RunServer(environ, start_...

详解安装mitmproxy以及遇到的坑和简单用法

详解安装mitmproxy以及遇到的坑和简单用法

mitmproxy 是一款工具,也可以说是 python 的一个包,在命令行操作的工具。 MITM 即中间人攻击(Man-in-the-middle attack) 使用这个工具可以在...