【问题标题】:Why Python print is not working properly in Windows prompt?为什么 Python 打印在 Windows 提示符下无法正常工作?
【发布时间】:2016-03-24 08:30:12
【问题描述】:

首先,我是 Python 的新手。我有这个打印行,它在 Python shell 中按预期工作,但在 Windows 7 Pro 命令提示符下没有。这是在循环中重复的代码:

print(format(line_number + 1, '2.0f') + " " +\
      formatted_datelst[0])

在 Python shell 中,我得到了这个(预期的): Python Shell output

在 Windows 7 Pro 命令提示符下,我得到了这个(意外): Windows 7 Pro command prompt output

正如您在 Windows 提示中看到的,行号没有被打印。更奇怪的是,在 Windows 7 Home 命令提示符下,我确实得到了预期的输出。有什么想法吗??

【问题讨论】:

    标签: python windows printing output prompt


    【解决方案1】:

    没关系,我自己找到的。

    我无意中在formatted_datelst[0] 的开头传递了一个回车代码\r。在 Windows 7 Home 机器中,这已被我用于输入文件的文本编辑器自动删除。 (正如我所说,我是 Python 的新手 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多