2011-03-17 87 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加上一些預處理指令。

相關問題