dictionary - 在 Cython 中返回字典的函数的声明
问题描述
在 Cython 中,我可以声明一个返回整数的函数:
cdef int fx(int myInt):
return myInt
与此处记录的所有数据类型相同。
一个返回整数数组的函数:
cdef int[:] fx():
...
return myIntArray
是否可以声明一个返回字典的函数?如何?
谢谢!
免责声明:我是 cython 的新手。请评论或编辑我的错误。
解决方案
至少对于从 python 调用函数,是dict
例如字典.pyx
# function can be called in cython
cdef dict print_dict():
cdef dict a
a = {'a':'areli', 'b':'asdasd'}
return a
# function to be called in python
def test_dict():
return print_dict()
在蟒蛇中:
import Dict
Dict.test_dict()
给出:
{'a': 'areli', 'b': 'asdasd'}
推荐阅读
- godot - 在第 0 行解析 JSON 时出错:应为“}”
- woocommerce - 有没有办法将简码的内容直接获取到描述 woocommerce?
- javascript - 来自内部组件的 Material UI Dialog 关闭对话框
- javascript - Hyperledger Fabric - 在 JavaScript 中计算 data_hash
- php - Laravel 返回 InvalidArgumentException 并显示消息“没有为 [graphql-playground] 定义提示路径”
- animation - CSS 过渡在不透明度淡出时跳跃
- python - xticks 范围内的 Seaborn 线图意外行为
- python - DJANGO 媒体图像未显示
- python - Odoo 14 错误:与数据库的连接失败并且用户的密码验证失败
- javascript - 在不丢失索引的情况下搜索 JS 数组 - 工作 Codepen Demo 使用 fetch() 和 Alpine.js