《Python编程快速上手—让繁琐工作自动化》第15章实践项目

15.12.1 美化的秒表

import time,pyperclip

print('Press ENTER to begin. Afterwards, press ENTER to click the stopwatch,\
Press Ctrl-C to quit.')
input()
print('Started')
startTime = time.time()
lastTime = startTime
lapNum = 1
copyText = ''


try:
    while True:
        input()
        lapTime = round(time.time() - lastTime,2)
        totalTime = round(time.time() - startTime,2)
#以下text两种不同的格式化都行
        #text = 'lap #{:>3}:{:>8} ({:>5})'.format(str(lapNum),str(totalTime),\
                                             #str(lapTime)) 
        text = 'lap #' + str(lapNum).rjust(3) + ':' + str(totalTime).rjust(8)+\
              ' ' + '(%s)' % str(lapTime).rjust(5) 
        copyText += text + '\n'
        pyperclip.copy(copyText)        
        print(text)
        
                        
        lapNum += 1
        lastTime = time.time()
except KeyboardInterrupt:
    print('\nDone')

15.12.2 计划的Web漫画下载

并没有写

你可能感兴趣的:(《Python编程快速上手—让繁琐工作自动化》第15章实践项目)