用Python写a穿过#
2016-12-16 16:23
120 查看
可以实现的功能是字符a动态穿越了 20个#
展现的是
sys.stdout.write(),和print类似,但是不会换行
\r覆盖打印
sys.stdout.flush()写入硬盘,不然sys.stdout.write()只会写入缓存,看不到输出
异常捕获。当程序在sleep(0.5)的时候,捕获到ctl+c键盘终端,不打印错误信息退出
展现的是
sys.stdout.write(),和print类似,但是不会换行
\r覆盖打印
sys.stdout.flush()写入硬盘,不然sys.stdout.write()只会写入缓存,看不到输出
异常捕获。当程序在sleep(0.5)的时候,捕获到ctl+c键盘终端,不打印错误信息退出
#!/usr/bin/env python import time import sys sys.stdout.write('\r'+ '#'*20) sys.stdout.flush() count = 0 while True: sys.stdout.write('\r'+ '#' * count + 'a') sys.stdout.flush() count += 1 try: time.sleep(0.5) except KeyboardInterrupt: print '\nexit' break if count == 20: sys.stdout.write('\r'+'#' * 20) sys.stdout.flush() count = 0
相关文章推荐
- C++ Boost 之Python(生成一个扩展模块)
- Python指南--数据结构
- Python指南--数据结构
- 搭建Python的集成开发环境WingIDE
- Python指南--深入流程控制
- Python指南--深入流程控制
- 用Python实现数据库编程
- Python指南--开胃菜
- Python指南--开胃菜
- Python指南--初步认识Python
- Python指南--初步认识Python
- Python指南--前言
- Python指南--使用Python解释器
- Python指南--使用Python解释器
- Python指南--前言
- python库lxml在linux和WIN系统下的安装
- C++ Boost 之Python(一个简单的例子)
- C++ Boost 之Python(继承)
- C++ Boost 之Python(大纲)