惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
GbyAI
GbyAI
B
Blog
F
Fortinet All Blogs
T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
Google Developers Blog
A
About on SuperTechFans
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog
B
Blog RSS Feed

博客园 - USEGEAR

学习unigui【48】lucksheet表格的显示object 学习使用:创建 Python 可调用的 Delphi 函数【4】 学习使用TPythonDelphiVar组件 数据交换Delphi与Python传值【3】 学习使用 数据交换 Delphi 与 Python 传值【2】 学习使用 Python4Delphi 是什么【1】 学习unigui【47】扫码安装apk 学习unigui【46】让客户端浏览器可以选下载你的apk 学习unigui【45】UnimDatePicker等按钮汉化崩溃 学习unigui【44】如何和uinHTMLFrame打交道 学习unigui【43】如何和控件打交道 学习unigui【42】UnimDatePicker的使用 学习unigui【41】htmlframe的交互现象 学习unigui【40】加入监控墙-1 头大的内存泄漏 学习unigui【39】单独文件在ms win server 上执行的坑 学习unigui【38】重新认识UUNIGUI--为什么这样快? 站在“架构与性能”层面重新审视 学习unigui【37】nginx的反向代理 ,程序中的重新定向 学习unigui【36】把数据导航放在Unidbgrid脚中 学习unigui【35】dbgrid字段宽度自适应 KingSADA的工业历史数据库的访问
学习使用 处理Python对象和列表【5】
USEGEAR · 2026-02-12 · via 博客园 - USEGEAR
//操作 Python 列表
procedure TForm1.WorkWithPythonList;
var
  PyList, PyItem: PPyObject;
  I: Integer;
begin
  PythonEngine1.LoadDll;
  
  // 【第1段】创建 Python 列表
  PyList := PythonEngine1.PyList_New(0);  // 空列表
  
  // 【第2段】向列表添加元素
  for I := 1 to 5 do
  begin
    PyItem := PythonEngine1.PyLong_FromLong(I * 10);
    PythonEngine1.PyList_Append(PyList, PyItem);
    PythonEngine1.Py_DecRef(PyItem);  // 列表已引用,可以释放临时引用
  end;
  
  // 【第3段】将列表注入 Python
  PythonEngine1.PyDict_SetItemString(
    PythonEngine1.GetMainModule.__dict__,
    'my_list',
    PyList
  );
  PythonEngine1.Py_DecRef(PyList);
  
  // 【第4段】Python 中使用列表
  PythonEngine1.ExecString(
    'print(f"列表: {my_list}")' + sLineBreak +
    'print(f"总和: {sum(my_list)}")'
  );
end;