0

I'm having a problem which can be exemplified by this python (3) code:

def askname():
 	sys.stdout.write("What is your name? ")
 	x = sys.stdin.readline()
	sys.stdout.write("Hello, "+x)

When I run it, I expect to get the prompt, type in my name, and then get the greeting. Instead, it prompts for the line first, then prints both the prompt and greeting afterward. I tried this:

sys.stdin._line_buffering = False

sys.stdout._line_buffering = False

but to no avail.

Any ideas?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jlm699
0

I believe sys.stdout.flush() is what you're looking for. Those stdio handles are just like open file handles

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.