2015-06-02 37 views
3

我有一個從.NET應用程序接收數據的Python腳本。如何在我的腳本中使用'System.Collections.Generic.List`1 [System.Byte]'類型的傳入緩衝區?在Python中使用System.Collections.Generic.List`1 [System.Byte]

腳本的功能是查找和替換字符串標記,將緩衝區重新組裝回System.Collections.Generic.List`1 [System.Byte],然後將緩衝區返回給.NET服務器。

新到Python。這是我到目前爲止:

import array 
import clr 
from System.Collections.Generic import * 

def SetRecvBuffer(buffer): 
    li = List[byte](buffer) 
    hookme.Debug(li)  
    for x in li: 
     hookme.Debug(x) 

任何幫助,將不勝感激。謝謝!

回答

0

的問題是,C#List初始化在Python端忽略括號中給出的項目,它看起來像一個bug,現在改用List.Add()

import clr 
clr.AddReference("System.Collections") 
from System.Collections.Generic import List 
from System import Int32 

li = List[Int32](range(3)) 
list(li) #returns [] 
li.Add(5) 
list(li) #returns [5] 
+0

https://github.com/pythonnet/pythonnet/問題/ 97 – denfromufa

相關問題