Eclipse and Python 3: why printf () from ctypes is displayed on console output after subsequent print () statements

I am running Eclipse with PyDev and Python 3.2 on Windows Vista and have been working on a tutorial on Python and ctypes.

However, I found that when I call msvcrt.printf () to print a line, it does not appear on the console output for Eclipse until all other print statements appear. A.

Here is the exact code I'm using:

from ctypes import *

msvcrt = cdll.msvcrt
message_string = "Hello Worlds!\n"

printf = msvcrt.printf
print(printf("Testing: %s".encode('ascii'),message_string.encode('ascii')))


print("foo")

print("why!?")

and here is the result:

23
foo
why!?
Testing: Hello Worlds!

The only explanations I saw elsewhere (for C in general) mention how printf is buffered and a new line is required before displaying, but there is a new line in the line, and I also added it directly to the printf ('printf ( "Testing:% s \ n", ... "), and that didn't matter.

Eclipse, , , ? ?

+5
2

C , stdout , , . , fflush printf:

msvcrt.fflush(msvcrt.stdout)

stdout :

msvcrt.setvbuf(msvcrt.stdout, None, _IONBF, 0)
+1

, printf 23, , sprintf, .

mscvcrt printf, python.

0

All Articles