我對ctypes有一個有趣的問題;雖然它似乎可以在普通的Python腳本中工作,但當我在printf()中使用它時,它會在字符串本身之後打印字符串的長度。演示:ctypes在Python解釋器中行爲奇怪
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> libc = CDLL("libc.so.6")
>>> libc.printf("Test")
Test4
>>> int = 55
>>> libc.printf("Test %d", int)
Test 557
>>> int = c_int(55)
>>> libc.printf("Test %d", int)
Test 557
有沒有人知道爲什麼會發生這種情況?
只是注意 - 而'int'是不是保留字,其實它是一個內置的屬性。你不應養成爲它分配參考的習慣。 – 2010-08-25 18:16:26
我知道,但這只是一個小解釋測試。 – 2010-08-25 18:18:32