CyManSAP CyManSAP - 11 months ago 77
Python Question

Input problems in cmd

I'm having a problem where if I run my python program in the windows terminal, text with inserted variables (

) have wacky results, where as in the python shell it works fine.


print("Hi! What's your name?")
name = input("name: ")
print("Nice to meet you %s" % name)
print("%s is a good name." % name)
print("This line is only to test %s in the middle of the text." % name)
input("press enter to exit")

Result in python shell:

Python Shell Result

Result in cmd:

cmd result

I'm using Windows 10 and python32 in case you needed to know.


This is a bug in the original 3.2.0 on Windows. The input() statement stripped off the "\n" but not the '\r', so the string input is hidden.


Quick fix:

name = input("name: ").rstrip()

It was fixed in 3.2.1. You really should upgrade your Python!