简体   繁体   English

从 GNU Radio Companion 中的嵌入式 Python 程序中打印

[英]Printing from within an embedded Python program in GNU Radio Companion

I am using an embedded Python program to take an average of a large number of spectra in GNU radio Companion.我正在使用嵌入式 Python 程序对 GNU radio Companion 中的大量频谱进行平均。 I want to continuously print the number of averaged spectra so that output happens on a same line, always overwriting the previous number.我想连续打印平均光谱的数量,以便 output 发生在同一行,总是覆盖以前的数字。 So not printing each number on a separate line.所以不要在单独的行上打印每个数字。

In Python you can do it in the following way:在 Python 中,您可以通过以下方式进行操作:

for i in range(100000):
    print('Number of spectra averaged  ', i, end='\r')

However, that does not work from within an embedded Python program, each number is on its own line, which is very time consuming.但是,这在嵌入式 Python 程序中不起作用,每个数字都在自己的行中,这非常耗时。

I thought that the escape character '\r' causes the problem, but probably not because the escape character '\n' works as it should be when printing from within a Python program.我认为转义字符 '\r' 会导致问题,但可能不是因为从 Python 程序中打印时,转义字符 '\n' 可以正常工作。

I have tried all the tricks I have found for printing the output on a single line, but none of them works for an embedded Python program.我已经尝试了所有在一行上打印 output 的技巧,但它们都不适用于嵌入式 Python 程序。

The printing from the embedded Python program goes both to the terminal where I started gnuradio-companion, and to the console of the gnuradio-companion.来自嵌入式 Python 程序的打印既可以发送到我启动 gnuradio-companion 的终端,也可以发送到 gnuradio-companion 的控制台。 In both cases the printing produces several lines, not a single line which would be always overwritten.在这两种情况下,打印都会产生多行,而不是始终被覆盖的单行。

How to print on a single line, overwriting the previous output?如何单行打印,覆盖之前的output? I am using GRC 3.9.5.0 (Python 3.8.10) on Ubuntu 22.04.4我在 Ubuntu 22.04.4 上使用 GRC 3.9.5.0 (Python 3.8.10)

Cheers, Kimmo干杯,基莫

Thanks Marcus谢谢马库斯

Yes, I was referring to the 'mini-terminal' or 'log-terminal' in GRC.是的,我指的是 GRC 中的“迷你终端”或“日志终端”。

Using QT GUI Number Sink works fine.使用 QT GUI Number Sink 工作正常。 I just added one more output (of the type float because Number Sink cannot receive integer value inputs) to the Python block, and directed it to Number Sink.我刚刚在 Python 块中添加了一个 output(浮点类型,因为 Number Sink 无法接收 integer 值输入),并将其定向到 Number Sink。

In the Number Sink I am using 'Update period = 0.5' because if using a value of zero the CPU load is increasing by about 10%在 Number Sink 中,我使用“更新周期 = 0.5”,因为如果使用零值,CPU 负载将增加约 10%

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM