python中print的不换行即时输出解决方案
来源:互联网 发布:记事本是什么软件 编辑:程序博客网 时间:2024/04/29 06:56
http://hi.baidu.com/esbat/blog/item/3e811c4ca1a455e1d62afc5a.html
本文原创自esbat的博客,转载请注明出处
python中的print默认是换行的
想要不换行输出有两种办法:
1.print后加上","
############################
>>>print "Hello World",
############################
2.使用sys.stdout.write命令
############################
>>>sys.stdout.write("Hello World")
############################
但是,以上的命令在具体执行时,并不会实时显示,每次都是在换行时才把整行指令打出来.
如果要实时显示,需要在每次sys.stdout.write后面加上一行sys.stdout.flush()让屏幕输出
############################
sys.stdout.write("Hello World")
sys.stdout.flush()
sys.stdout.write("one line!")
sys.stdout.flush()
############################
附一段我用来控制write换行情况的代码
############################
class ChangeLine:NewLine = True
@classmethod
def write_out(self,str,typename = 0):
# 0 is "\n.....\n"
if typename == 0:
if self.NewLine == False:
sys.stdout.write('\n')
sys.stdout.flush()
sys.stdout.write(str + '\n')
sys.stdout.flush()
self.NewLine = True
# 1 is "......."
if typename == 1:
sys.stdout.write(str)
sys.stdout.flush()
self.NewLine = False
# 2 is "\n......"
if typename == 2:
if self.NewLine == False:
sys.stdout.write('\n')
sys.stdout.flush()
sys.stdout.write(str)
sys.stdout.flush()
self.NewLine = False
# 3 is "......\n"
if typename == 3:
sys.stdout.write(str + '\n')
sys.stdout.flush()
self.NewLine = True
############################
- python中print的不换行即时输出解决方案
- python中print的不换行即时输出解决方案
- Python print 输出不换行
- python中print不换行的方法
- python中print不换行
- python print 不输出换行符
- python print输出不自动换行
- Python print输出不换行没空格
- Python print 输出打印不换行
- python print不换行(更改print的默认输出格式)
- Python print 不换行的方法
- Python3 print 不输出换行
- Python print 不换行打印
- Python print 不换行打印
- Python print打印不换行
- Python print 不换行打印
- Python Print 打印不换行
- Python: print 不换行打印
- Android OpenGL ES 简明开发教程三:3D绘图基本概念
- 24小时时分秒重合的次数
- Android OpenGL ES 简明开发教程四:3D 坐标变换
- android videoView 按不同比例缩放
- C语言出错中英文对照表
- python中print的不换行即时输出解决方案
- 有趣的计算机字符编码(转载)
- 关于hibernate联合(单个)主键查询语句返回值为空的问题
- 安装vss6.0过程中出现“error launching ***\acmboot.exe”的解决方案
- QT 中文支持
- 雷锋读图:87%的平板用户通过平板进行节日购物
- JFreeChart 图表生成
- input输入框的各种样式
- phpMyAdmin使用教程