1 回答
TA贡献1890条经验 获得超9个赞
>>> from ctypes import *
>>> libc=cdll.msvcrt
>>> libc.printf("hello %s\n","world")
hello world
12
>>>
>>> p = create_string_buffer("Hello", 30)
>>> n=libc.sprintf(p,"hello %s\n","world")
>>> n
12
>>> print p
<ctypes.c_char_Array_30 object at 0x02247C10>
>>> dir(p)
['__class__', '__ctypes_from_outparam__', '__delattr__', '__delitem__', '__delsl
ice__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__',
'__getslice__', '__hash__', '__init__', '__len__', '__module__', '__new__', '__r
educe__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__setslice
__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
'_b_base_', '_b_needsfree_', '_length_', '_objects', '_type_', 'raw', 'value']
>>> p.value
'hello world\n'
>>>
添加回答
举报