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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.