导航:首页 > 编程语言 > python实现计时功能

python实现计时功能

发布时间:2022-08-04 22:23:03

python 怎么计时

import time
s = 0
while(True):
time.sleep(1)
s = s+1
print(s)
--------------------
新手献丑

㈡ 用python 计时器怎么做,

用python实现计时器功能,代码如下:

'''SimpleTimingFunction.

previouscall.ItworkswithmostPython2.xplatforms.Thefunction
(clock)without
usingaglobalvariable.
'''
importtime
defr(op=None,clock=[time.time()]):
ifop!=None:
ration=time.time()-clock[0]
print'%sfinished.Duration%.6fseconds.'%(op,ration)
clock[0]=time.time()
#Example
if__name__=='__main__':
importarray
r()#Initialisethetimingclock
opt1=array.array('H')
foriinrange(1000):
forninrange(1000):
opt1.append(n)
r('Arrayfromappend')
opt2=array.array('H')
seq=range(1000)
foriinrange(1000):
opt2.extend(seq)
r('Arrayfromlistextend')
opt3=array.array('H')
seq=array.array('H',range(1000))
foriinrange(1000):
opt3.extend(seq)
r('Arrayfromarrayextend')
#Output:
#Arrayfromappendfinished.Duration0.175320seconds.
#Arrayfromlistextendfinished.Duration0.068974seconds.
#Arrayfromarrayextendfinished.Duration0.001394seconds.

㈢ python的计时器

你可以用Twisted来实现,源代码如下:

from twisted.internet import task
from twisted.internet import reactor

#set global variables
g = 0
def run():
global g
g = g + 1
print 'the global value g is:%s'%g
#add function run to twisted's looping call
l = task.LoopingCall(run)
#set interval to 5*60 seconds
l.start(5*60)
reactor.run()
要运行这段代码你得装twisted和zope中关于interface的定义,上google搜搜载一个装了就可以了。

㈣ Python2.7.13怎么编计时器

用python实现计时器功能,代码如下:

''SimpleTimingFunction.

previouscall.ItworkswithmostPython2.xplatforms.Thefunction
(clock)without
usingaglobalvariable.
'''
importtime
defr(op=None,clock=[time.time()]):
ifop!=None:
ration=time.time()-clock[0]
print'%sfinished.Duration%.6fseconds.'%(op,ration)
clock[0]=time.time()
#Example
if__name__=='__main__':
importarray
r()#Initialisethetimingclock
opt1=array.array('H')
foriinrange(1000):
forninrange(1000):
opt1.append(n)
r('Arrayfromappend')
opt2=array.array('H')
seq=range(1000)
foriinrange(1000):
opt2.extend(seq)
r('Arrayfromlistextend')
opt3=array.array('H')
seq=array.array('H',range(1000))
foriinrange(1000):
opt3.extend(seq)
r('Arrayfromarrayextend')
#Output:
#Arrayfromappendfinished.Duration0.175320seconds.
#Arrayfromlistextendfinished.Duration0.068974seconds.
#Arrayfromarrayextendfinished.Duration0.001394seconds.

题主空闲的时候可以多看看Python的相关教程,黑马程序员再往上有许多免费的教程,想学习的可以下载下来多看看,多学习学习,以后类似的问题就可以迎刃而解了。https://..com/question/1051689931722045579.html?fr=android_app&share_time=1499421328373

㈤ python怎么写计时器用面向对象和多向进程

timeit

㈥ python计时器问题

import time
print('按下回车开始计时,按下 Ctrl + C 暂停/停止计时。')
while True:
input("")
starttime = time.time()
print('开始')
pausetime=0
while True:
try:
totaltime=int((time.time()-pausetime-starttime))
print('【'+str(int((time.time()-pausetime-starttime)*0.66)),'进度】',int((time.time()-pausetime-starttime)/60),'分', int((time.time()-pausetime-starttime)%60), '秒',end=' ')
time.sleep(1)
except KeyboardInterrupt:

print('【' + str(int((time.time() -pausetime- starttime) * 0.66)), '进度】', int((time.time()-pausetime - starttime) / 60), '分',
int((time.time() -pausetime- starttime) % 60), '秒', '...暂停中 按回车继续,输入Q停止计时',end=' ') pausetime_start=time.time()

s=input("")
if s.strip().upper()=='Q':
pausetime_end = time.time()
pausetime = pausetime_end - pausetime_start + pausetime
print('结束')
endtime = time.time()
print('总时间:', round(endtime - pausetime - starttime, 2), '秒 ')
exit(0)
elif s.strip().upper()=='':
pausetime_end=time.time()
pausetime=pausetime_end-pausetime_start+pausetime

㈦ 使用Python,实现程序运行计时的数码管表示

用python实现计时器功能,代码如下:
''' Simple Timing Function.
This function prints out a message with the elapsed time from the
previous call. It works with most Python 2.x platforms. The function
uses a simple trick to store a persistent variable (clock) without
using a global variable.
'''
import time
def r( op=None, clock=[time.time()] ):
if op != None:
ration = time.time() - clock[0]
print '%s finished. Duration %.6f seconds.' % (op, ration)
clock[0] = time.time()
# Example
if __name__ == '__main__':
import array
r() # Initialise the timing clock
opt1 = array.array('H')
for i in range(1000):
for n in range(1000):
opt1.append(n)
r('Array from append')
opt2 = array.array('H')
seq = range(1000)
for i in range(1000):
opt2.extend(seq)
r('Array from list extend')
opt3 = array.array('H')
seq = array.array('H', range(1000))
for i in range(1000):
opt3.extend(seq)
r('Array from array extend')
# Output:
# Array from append finished. Duration 0.175320 seconds.
# Array from list extend finished. Duration 0.068974 seconds.
# Array from array extend finished. Duration 0.001394 seconds.

㈧ python 如何添加计时器

使用time模块
程序最开始的时候使用time.time()得到一个时间
然后,再需要查看时间的地方调用一下time.time(),得到另一个时间,然后两个时间相减就可以得到程序执行的时间,得到的是秒数,可以自己算一下得到分钟这类的

阅读全文

与python实现计时功能相关的资料

热点内容
农行app怎么开网银 浏览:649
java迭代器遍历 浏览:301
闽政通无法请求服务器是什么 浏览:48
怎么做积木解压神器 浏览:203
王者荣耀解压玩具抽奖 浏览:49
12位是由啥加密的 浏览:868
程序员编迷你世界代码 浏览:895
php取现在时间 浏览:246
单片机高吸收 浏览:427
怎么区分五代头是不是加密喷头 浏览:244
hunt测试服务器是什么意思 浏览:510
2013程序员考试 浏览:641
毕业论文是pdf 浏览:736
服务器跑网心云划算吗 浏览:471
单片机定时器计数初值的计算公式 浏览:801
win7控制台命令 浏览:567
猫咪成年app怎么升级 浏览:692
360有没有加密软件 浏览:315
清除cisco交换机配置命令 浏览:751
华为删除交换机配置命令 浏览:473