You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code及Jupyter Notebook中同屏打印失效,\b与\r无法正常工作

VS Code Jupyter扩展与Jupyter Notebook中控制字符失效问题

在VS Code(已安装Jupyter Notebook扩展)和Jupyter Notebook环境下,无法实现同屏打印效果:

  • \b退格符无法正常工作,必须成对使用才能达到退格效果
  • \r回车符也无法实现预期的行首覆盖功能

相同代码在终端运行时一切正常,以下是问题复现的代码及异常输出:

复现代码1(\r失效)

import time

def test_output():
        print('\b\b \b\b: OK', end='', flush=True)
        print(' -> Read: OK', end='', flush=True)
        print(' -> Json: OK', end='', flush=True)
        print(' -> Analysing...', end='', flush=True)


for i in range(15):
    print(f'\r{" " * 20}\r', end="", flush=True)
    time.sleep(1.5)
    print(f"\rtest({i:02d}/15): Opening", end="", flush=True)
    time.sleep(1.5)
    test_output()

异常输出1

test(14/15): OpeningK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing: OK -> Read: OK -> Json: OK -> Analysing...

复现代码2(\b失效)

import time

def test_output():
        print('\b\b\b: OK', end='', flush=True)
        print(' -> Read: OK', end='', flush=True)
        print(' -> Json: OK', end='', flush=True)
        print(' -> Analysing...', end='', flush=True)


for i in range(15):
    print(f'\r{" " * 20}\r', end="", flush=True)
    time.sleep(1.5)
    print(f"\rtest({i:02d}/15): Opening", end="", flush=True)
    time.sleep(1.5)
    test_output()

异常输出2

test(14/15): Opening OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing..: OK -> Read: OK -> Json: OK -> Analysing...

内容的提问来源于stack exchange,提问作者GBEYOND

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 06:02:53