Search code examples
pythonwindowsprintingoutputprompt

Why Python print is not working properly in Windows prompt?


First of all I'm a newbie in Python. I have this print line that works as expected in the Python shell but not in the Windows 7 Pro command prompt. This is the code that repeats inside a loop:

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

In the Python shell I get this (expected): Python Shell output

In the Windows 7 Pro command prompt I get this (unexpected): Windows 7 Pro command prompt output

As you can see in the Windows prompt the line number is not being printed. Even more strange, in the Windows 7 Home command prompt I do get the expected output. Any ideas??


Solution

  • Never mind, I found it myself.

    I was inadvertently passing a carriage return code \r in the beginning of formatted_datelst[0]. In the Windows 7 Home machine this had been removed automatically by a text editor I had used for the input file. (As I said, I'm a newbie in Python :)