user3313834 user3313834 - 2 years ago 93
Python Question

pythran export dict with tuples as key

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}

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 I get this error:

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download