pythran export dict以元组为关键 [英] pythran export dict with tuples as key
本文介绍了pythran export dict以元组为关键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在需要int数组的函数中使用pythran,对于第二个arg,使用int的元组作为键,并将int作为值:
I try to use pythran in a function that need an int array and for the second arg a dict with tuples of int as keys and an int as value:
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}
有关dict的详细信息,请参阅 pythran 的正确方法:
What is the correct way to inform pythran about the 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
With (int ,int):int dict 我收到这个错误:
With (int, int):int dict I get this error:
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
推荐答案
从你的回溯,它似乎您正在导入 sys
。在这种情况下,pythran尝试获取导入模块的源来编译它。由于 sys
是一个内置模块,它失败。
From your backtrace, it seems you're importing sys
. In that kind of situation, pythran tries to get the source of the import module to compile it. As sys
is a built-in module, it fails.
这篇关于pythran export dict以元组为关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文