开发者

Dynamically build and return a Python list in a C Python extension

开发者 https://www.devze.com 2022-12-13 22:40 出处:网络
I\'m writing a Python extension 开发者_C百科in C, and I\'m trying to figure out how to dynamically build and return a Python list using my extension.I know how to build a list of predetermined size us

I'm writing a Python extension 开发者_C百科in C, and I'm trying to figure out how to dynamically build and return a Python list using my extension. I know how to build a list of predetermined size using Py_BuildValue. Is there a way to create a list with Py_BuildValue then append items to that list? Is there a different, and better, alternative?


How about using PyList_Append, just like (modulo reference management and whatnot) you'd use .append in Python?

Looking at the list API docs may help as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消