python例题出错。我的版本是3.2
照着帮助里的例题打:
>>>from ctypes import *
>>> class cell(Structure):
... pass
...
>>> cell._fields_ = [("name", c_char_p),
... ("next", POINTER(cell))]
>>>c1 = cell()
>>> c1.name = "foo"
结果报这个错误:typeError:string or integer address expected instead of str instance
不知道哪有问题,请高手赐教
>>>from ctypes import *
>>> class cell(Structure):
... pass
...
>>> cell._fields_ = [("name", c_char_p),
... ("next", POINTER(cell))]
>>>c1 = cell()
>>> c1.name = "foo"
结果报这个错误:typeError:string or integer address expected instead of str instance
不知道哪有问题,请高手赐教
作者: wobuzhidaotashishui 发布时间: 2011-05-23
自己解决,应为是3.2版本,要显示转化,所以字符串前面要加‘b’,把str变成byte
作者: wobuzhidaotashishui 发布时间: 2011-05-23