【问题标题】:Is it possible to prevent VISUAL STUDIO from automatically adding new line in DEBUG CONSOLE?是否可以防止 VISUAL STUDIO 在 DEBUG CONSOLE 中自动添加新行?
【发布时间】:2019-04-14 20:37:14
【问题描述】:

当我在 VSC 上运行此代码时:

numbers = [8, 18, 2, 4]
maxlen=len(numbers)
i=0
while i<maxlen:
    print (i, numbers[i])
    i=i+1

我将 PRINT 函数的每个输出放在单独的行中。我试过使用 'end' 这样的参数:

print(i, numbers[i], end=' ')

但没有成功。

Jupyter 上执行的相同代码看起来不错。

在这里您可以找到两个编辑器的屏幕:

Jupyter output

Visual Studio Code output

非常感谢任何提示!

【问题讨论】:

    标签: python vscode-debugger


    【解决方案1】:

    试试 format()。 它将为每一行创建一个字符串。 print('{0} {1}'.format(i, numbers[i]))

    【讨论】:

    • 一个非常奇怪的问题的非常好的解决方案。使用 format() 后,我能够将输出对齐为两行,看起来好多了。所以我添加了 end = ' ' 参数,它工作得很好。行之间没有多余的空行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多