ctypes — 用于 Python 的外来函数库

源代码: Lib/ctypes


ctypes 是用于 Python 的外部函数库。它提供 C 兼容数据类型,且允许调用 DLL 或共享库中的函数。可以使用它以将这些库包裹在纯 Python 中。

ctypes 教程

注意:本教程中的代码样本使用 doctest to make sure that they actually work. Since some code samples behave differently under Linux, Windows, or macOS, they contain doctest directives in comments.

注意:某些代码样本引用 ctypes c_int 类。当平台 sizeof(long) == sizeof(int) ,它是别名化的 c_long 。因此,不应该感到困惑若 c_long 被打印若期望 c_int — 它们实际上是同一类型。