我有一本字典,使用在用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
哦,真抱歉。我删除了评论,因为我发现它的工作。对不起, –