Windows Python IDEL编译器自动忽略'\r'及简单进度条的实现
来源:互联网 发布:nginx 子域名 重定向 编辑:程序博客网 时间:2024/06/05 08:44
Windows环境下,Python自带的IDEL编译器在进行字符串输出时会忽略字符串结尾的'\r'导致光标无法回到行首。
另在DOS窗口下采用Python print.py运行 运行的结果正确。
附简单进度条代码。
使用'\r'回到行首和sys.stdout.write/flush输出并刷新缓冲区。
注意特殊字符实心方块的编码方式。
# coding=utf-8import sys,timet = "▉"t = t.decode("utf-8")class ProgressBar: def __init__(self, count = 0, total = 0, width = 20): self.count = count self.total = total self.width = width def move(self): self.count += 1 def log(self, s): progress = self.width * self.count / self.total sys.stdout.write('{0:3}/{1:3}: \r'.format(self.count, self.total)) sys.stdout.flush() sys.stdout.write(t* progress + '--' * (self.width - progress)+'\r') print s if progress == self.width: sys.stdout.write('Done!') else : sys.stdout.write('Please waitting!\n\r')num = 10bar = ProgressBar(total=num)for i in range(num): bar.move() bar.log('%2d'%((float)(i+1)/num*100)+'%\r') time.sleep(1)
0 0
- Windows Python IDEL编译器自动忽略'\r'及简单进度条的实现
- python自带IDEL简单操作
- python IDEL 使用
- Python ---IDEL清屏
- python在线编译器的简单原理与超简单实现
- 进度条的简单实现
- 进度条的简单实现
- 简单进度条的实现
- 简单进度条的实现
- R语言自动提取新闻摘要的简单实现
- 用超简单的python代码实现Java在线编译器
- Linux(三):简单进度条的原理及实现
- Windows Phone Silverlight 音乐进度条简单实现
- Python IDEL整体代码缩进
- LINUX实现简单的进度条
- 环形进度条的简单实现
- Linux实现简单的进度条
- 实现一个简单的进度条
- ACM训练计划
- JAVA中集合框架基础解析
- 常用查看网络的命令
- iOS 基本图形的绘制 基于bitmap 位图
- 数据库历史信息保存设计
- Windows Python IDEL编译器自动忽略'\r'及简单进度条的实现
- leetcode -- The Skyline Problem -- 难理解,关于heap
- c语言
- 今日笔记Linux命令的详解
- 一个表单多个按钮提交
- 正则表达式知识点总结
- 使用opencv 抠毛笔字
- android仿IOS7的两种对话框
- 2015跑过的路