import ctypes import sys class A(ctypes.Structure): _fields_ = [('b',ctypes.c_char * 1024)] print "Python version:", sys.version print "ctypes version:", ctypes.__version__ a = A() stringWithNulls = 'x\000y\000' print "string with nulls:" , stringWithNulls a.b = stringWithNulls print "a.b=", a.b # prints 'x' only print "type(a.b)", type(a.b) # str? buf = buffer(a) print "buffer contents, the 'y' is not copied:" for i in buf[:10]: print i, ord(i)