我有一本字典,使用在用Cython字典,尤其是裏面nogil
my_dict = {'a':[1,2,3], 'b':[4,5] , 'c':[7,1,2])
我想用這個字典中的用Cython內nogil功能。所以,我試圖宣佈它爲
cdef dict cy_dict = my_dict
到目前爲止還沒有。
現在我需要迭代my_dict的鍵,如果值在列表中,請遍歷它。在Python中,它很容易,如下所示:
for key in my_dict:
if isinstance(my_dict[key], (list, tuple)):
###### Iterate over the value of the list or tuple
for value in list:
## Do some over operation.
但是,在Cython裏面,我想要在nogil裏面實現相同的功能。因爲,python對象不允許在nogil內部,我都被卡在這裏。
with nogil:
#### same implementation of the same in Cython
任何人都可以幫我嗎?
謝謝。讓我看看。數據類型在字典裏面,我會把它保存爲列表。對於編譯,我可以遵循正常的Cython方式嗎? –
您需要按照[此處](http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#specify-language-in-setup-py)中所述的方式指定語言,但除此之外它應該正常工作辦法。 – DavidW
哦,真抱歉。我刪除了評論,因爲我發現它的工作。對不起, –