以元组为键的Pythran导出dict

2024-05-16 07:22:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在需要int数组的函数中使用Pythran,对于第二个参数,使用dict元组ints作为键,int作为值:

myarray = np.array([[0, 0], [0, 1], [1, 1],
                    [1, 2], [2, 2], [1, 3]])

dict_with_tuples_key = {(0, 1): 1, (3, 7): 1}

告诉Pythran关于dict的正确方法是什么?地址:

#pythran export update_dict((int, int):int dict, int[][])
def update_dict(dict_with_tuples_key, myarray):
    # do something with dict_with_tuples_key and myarray
    # return and updated dict_with_tuples_key
    return dict_with_tuples_key

使用(int,int):int dict我得到这个错误:

File "/usr/lib/python2.7/inspect.py", line 526, in findsource
  file = getfile(object)
File "/usr/lib/python2.7/inspect.py", line 403, in getfile
  raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'sys' (built-in)> is a built-in module

Tags: andkeyinreturnusrwithupdatedict
1条回答
网友
1楼 · 发布于 2024-05-16 07:22:21

从回溯来看,似乎您正在导入sys。在这种情况下,pythran试图获取导入模块的源代码来编译它。因为sys是一个内置模块,所以它失败了。

相关问题 更多 >