Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
while True: volts = adc.readADCDifferential01(4096, 8) print volts
这很好用,只是它会打印出一列电压,很快就会填满终端屏幕。我宁愿它并排打印电压并从左到右填充行。
我尝试在打印电压后加一个逗号,但屏幕上什么也没有显示,直到我按 control-C 停止程序。逗号确实会导致电压成行打印,但我需要实时观察读数,而不是盲目地等待,直到我怀疑测试完成。
为什么添加逗号会导致程序停止显示正在发生的电压?
Pythonstdout以行缓冲模式打开,因此当不打印换行符时,您不会看到列中打印的电压,直到刷新。
stdout
手动刷新缓冲区:
import sys while True: volts = adc.readADCDifferential01(4096, 8) print volts, sys.stdout.flush()