파이썬 2.5 미리보기 4편: ctypes

>>> import ctypes
>>> libc = ctypes.cdll.c
>>> libc.getosreldate()
600104
>>> buf = ctypes.c_buffer(30)
>>> libc.memset.restype = None
>>> libc.memset(buf, 5, 30)
>>> buf.raw
'\x05\x05\x05\x05\x05\x05\x05\x05...'
>>> libc.memset(buf, 45, 30)
>>> buf.raw
'------------------------------'
>>> ctypes.pythonapi.PyString_FromString.restype = ctypes.py_object
>>> ctypes.pythonapi.PyString_FromString(buf)
'------------------------------\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'

드디어 이전에 작업했던 대로 파이썬 2.5에 ctypes가 들어왔습니다. 🙂

벌써부터 uuid 모듈이나 앞으로 들어올 표준모듈에서도 ctypes를 활용할 것 같은 분위기입니다. platform 모듈에서도 쓸 수 있을 것 같고요~