我是靠谱客的博主 背后大门,这篇文章主要介绍python逐个打印字符串,在python的一行中动态打印字符串,现在分享给大家,希望可以做个参考。

I'm trying to print strings in one line.

I've found solutions but they don't works with windows correctly.

I have text file contains names and I want to print them like this

name=john then change john to next name and keep name=, I've made this code but didn't work correctly with windows:

op = open('names.txt','r')

print 'name=',

for i in op.readlines():

print 'r'+i.strip('n')

thank you for your time

解决方案

Using 'b' as suggested by senderle

import sys

import time

sys.stdout.write('name=')

last_lenght = 0

with open('names.txt') as names:

for name in names:

sys.stdout.write('b' * last_lenght) # go back

sys.stdout.write(' ' * last_lenght) # clear last name

sys.stdout.write('b' * last_lenght) # reposition

sys.stdout.write(name.strip())

sys.stdout.flush()

last_lenght = len(name.strip())

time.sleep(0.5)

最后

以上就是背后大门最近收集整理的关于python逐个打印字符串,在python的一行中动态打印字符串的全部内容,更多相关python逐个打印字符串,在python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部