a foreign function library for Python


  交大資工系103級
  戴嘉駿/darkgerm
  <darkgerm@gmail.com>
How can Python combine with
C?
 Python API
 Python built-in module - ctypes
 third party module (ex: boost.python, SWIG)
What is ctypes
 A foreign function library for Python.
 It provides C compatible data types.
 It allows calling functions in DLLs or shared
  libraries.
ctypes History
   1
Reasons to use ctypes
 more portable between implementations
  of Python.
 It has a much lower startup cost.
 It is in Python Standard Library.
 you're still writing Python!
Fundamenta data types
Structures and Unions
Example on stackoverflow
Example on stackoverflow
Example on stackoverflow
Example on stackoverflow
Example on stackoverflow
Example on stackoverflow
Example on stackoverflow
Modify the Example
Modify the Example
Modify the Example
Modify the Example
function prototypes
function prototypes
Who use ctypes?
Who use ctypes?
Who use ctypes?
Thank you for
        listening!!

Ref:
   http://docs.python.org/library/ctypes.html
   http://stackoverflow.com/questions/145270/calling-c-c-from-python
   http://stackoverflow.com/questions/135834/python-swig-vs-ctypes
   http://stackoverflow.com/questions/1942298/wrapping-a-c-library-in-
    python-c-cython-or-ctypes
   https://www.google.com/

Ctypes