简体   繁体   English

我正在尝试一次打印多行,每行在 python 2.7.11 中都有一个设定速度的延迟打印

[英]I am trying to print multiple lines at once, with each line having a delayed print of a set speed in python 2.7.11

Basically,基本上,

Delay Print 1延迟打印 1

Multiple lines at once test.一次测试多行。

The big brown fox jumped over the lazy dog.棕色的大狐狸跳过了懒惰的狗。

Should all print at the same time, while using this function应该同时打印,同时使用这个 function

import time
import sys

text_speed = raw_input("What speed? > ")

def delay_print(s):
    for c in s:
        sys.stdout.write(c)
        sys.stdout.flush()
        if text_speed == "fast":
            time.sleep(0.075)

        elif text_speed == "slow":
            time.sleep(.275)

        elif text_speed == "normal":
            time.sleep(.175)

delay_print("Delay Print 1 \n")
delay_print("Multiple lines at once test. \n")
delay_print("The big brown fox jumped over the lazy dog. \n")

Is that possible?那可能吗?

When I run it, it will delay print each string one after the other, but I can't seem to find a way to make all 3 lines print at once.当我运行它时,它会一个接一个地延迟打印每个字符串,但我似乎无法找到一种方法来一次打印所有 3 行。 Even without the delay print.即使没有延迟打印。

well it depends, the thing that is happening right now is that you are giving the order to execute 3 times the function with different attributes, but if I did understand you, you want to execute these 3 functions in a parallel way to each other so here is a reading you can use on multiprocessing http://docs.python.org/2/library/multiprocessing.html I hope it helps.好吧,这取决于,现在发生的事情是您下令执行 3 次具有不同属性的 function,但如果我确实理解您,您希望以并行方式执行这 3 个函数,所以这是您可以在多处理http://docs.python.org/2/library/multiprocessing.html上使用的阅读材料,希望对您有所帮助。

I'm not sure how you would make it 3 lines, but the program from this github link makes a progress bar in the console, and there are things after the part that moves, so you might be able to find a way to also add a new line in this setup.我不确定您如何将其设为 3 行,但是来自此 github 链接的程序会在控制台中生成一个进度条,并且在移动的部分之后有一些东西,因此您也许可以找到一种方法来添加此设置中的新行。

import math
import sys
import time

END = 170

MAX_LEN = 30

def get_progressbar_str(progress):
    BAR_LEN = int(MAX_LEN * progress)
    return ('[' + '=' * BAR_LEN +
            ('>' if BAR_LEN < MAX_LEN else '') +
            ' ' * (MAX_LEN - BAR_LEN) +
            '] %.1f%%' % (progress * 100.))

for i in range(END + 1):
    time.sleep(0.01)
    progress = 1.0 * i / END
    sys.stderr.write('\r\033[K' + get_progressbar_str(progress))
    sys.stderr.flush()
sys.stderr.write('\n')
sys.stderr.flush()

you might want to put this at the end so the console doesn't close out after.你可能想把它放在最后,这样控制台就不会关闭。

while True:
    time.sleep(1)

note: this has to be ran from a.py file, not from idle to see the progress bar properly.注意:这必须从 a.py 文件运行,而不是从空闲运行才能正确查看进度条。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何打印多行,然后让后续行分别替换每行(Python) - How can I print multiple lines, having subsequent lines replacing each of them independently (Python) 我试图在 python 中只打印文件的前 5 行 - I am trying to print only the first 5 lines of a file in python 尝试按顺序在python字典中打印多行 - Trying to print multiple lines in a python dictionary in order Python 3:将多行打印到一行 - Python 3: Print multiple lines to one line 我正在尝试使用line.split(&#39;\\ n)-&gt;无法识别行从类似文件的目录中打印一些关键行 - I am trying to print a few key lines from a directory of like files using line.split('\n) --> not recognizing lines 如何打印多行并使每条输出行不同? - How to print multiple lines and make each output line different? 如何在各行上打印列表的每个元素,在python中以行号开头? - How do I print each element of a list on individual lines, preceded by the line number in python? 我是 python 的新手,我想弄清楚如何在同一行上一次打印一个字母 - I'm new to python and I am trying to figure out how to print letters one at a time on the same line Python 3 在同一行上打印来自 try 语句的输出,我正在尝试学习线程 - Python 3 Print output from try statement on the same line and I am trying to learn threading 我正在尝试使用python脚本中的shell命令在目录中打印每个文件的最后一行 - I am trying to print the last line of every file in a directory using shell command from python script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM