This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ctype cant's use printf
Type: crash Stage:
Components: ctypes Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: FreedomKnight, georg.brandl
Priority: normal Keywords:

Created on 2013-10-12 12:02 by FreedomKnight, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg199552 - (view) Author: FreedomKnight (FreedomKnight) Date: 2013-10-12 12:02
the code is simple, so i paste all of mycode

    #!/usr/bin/env python3
    from ctypes import *

    cdll.LoadLibrary("libc.so.6")
    libc = CDLL("libc.so.6")
    libc.printf("hello\n")

result:
h

expect result:
hello

plateform:
fedora 19 x64
python3 (3.3.2)
msg199554 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-10-12 12:19
In Python 3, "hello\n" is a Unicode string. printf() expects a byte string, so you should use b"hello\n" (or s.encode() for string object named "s").
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63430
2013-10-12 12:19:11georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg199554

resolution: not a bug
2013-10-12 12:02:49FreedomKnightcreate