2011-03-17 86 views
2

CPython与.net c#PInvoke类似吗?Python有类似于.net c#PInvoke的东西吗?

例如我有some.dll或some.so,并希望在运行时注册一些函数,并开始在我的程序中使用它们。

在C#中,你可以这样做:

// Marshal.cs 
using System; 
using System.Runtime.InteropServices; 

namespace CSharpIterators 
{ 
    class MainClass 
    { 
     [DllImport("msvcrt.dll")] 
     public static extern int puts([MarshalAs(UnmanagedType.LPStr)] string m); 

     [DllImport("msvcrt.dll")] 
     internal static extern int _flushall(); 

     public static void Main (string[] args) 
     { 

      puts("Hello World!"); 
      _flushall(); 
     } 
    } 
} 

做Python有类似的功能?

在此先感谢!

回答

0

另一种选择是,以创建一个Python接口的C/C++代码使用的工具,就像痛饮: http://www.swig.org/

用于创建包装的语法非常类似于C加上一些预处理指令。

相关问题