printf returns 1 instead of “Hello World!” which is the desired result.
I googled it and think its because of the changes in the way sequences are treated.
How do I modify the code to print “Hello World!”?
http://www.mail-archive.com/python-3000@python.org/msg15119.html
import ctypes
msvcrt=ctypes.cdll.msvcrt
string=b"Hello World!"
msvcrt.printf("%s", string)
The first argument needs to be a byte string as well:
The return value of printf is the number of characters printed, which should be 12 in this case.
Edit:
If you want the string to be returned instead of printed, you can use
sprintfinstead. This is dangerous and NOT recommended.I don’t know why you’d want to do this though, since Python has its own string formatting.
sprintfis a dangerous method since it is susceptible to buffer overflows.