博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python For Delphi---更好地协同(续)
阅读量:4646 次
发布时间:2019-06-09

本文共 1014 字,大约阅读时间需要 3 分钟。

Delphi通过PythonForDelphi变量来和Python交换数据可以,有没有别的办法了呢?有,可以像COM一样来调用Python模块的变量和函数,这看起来好像能更酷一些 :-)

感谢samson,是他的一篇文章使我学习到了这个方法,并且很热心地给予了指教!

废话少说,先上Python代码(hello.py,放到程序目录下):

strPython='Hello,This is a python string !'dicPython={
'StringInfo':'Hello,This is a python string !'}lstPython=list('Hello,This is a python string !')def SayHello(s): return 'Hello,'+s

上面是简单的示例,有变量和函数,我们看看在Delphi中怎样来调用.

在Delphi中写下面的代码:

var  PyModule: variant;....  PyModule := Import('hello');  //测试Python变量传递  Memo1.Lines.Add(PyModule.strPython);  Memo1.Lines.Add(PyModule.dicPython);  Memo1.Lines.Add(PyModule.lstPython);  Memo1.Lines.Add(PyModule.SayHello('Garfield'));

执行后,在Delphi的Memo1中将看到下面的内容:

Hello,This is a python string !{'StringInfo': 'Hello,This is a python string !'}['H', 'e', 'l', 'l', 'o', ',', 'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 'p', 'y', 't', 'h', 'o', 'n', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', '!']Hello,Garfield

怎么样,是不是看起来也很方便?

 

转载于:https://www.cnblogs.com/GarfieldTom/archive/2013/01/17/2864589.html

你可能感兴趣的文章
kv.go
查看>>
利用截取字符串,生成已声明的字符串中的4位随机验证码。
查看>>
Spring 事务模型
查看>>
【MM系列】SAP S/4 HANA BP创建客户/供应商的一点想法
查看>>
【HANA系列】SAP HANA XS使用JavaScript数据交互详解
查看>>
【HANA系列】SAP HANA SQL获取上周的周一
查看>>
对称矩阵
查看>>
轮播图笔记!
查看>>
值类型与引用类型
查看>>
This kernel requires an x86-64 CPU, but only detected an i686 CPU.
查看>>
PAT 1023 Have Fun with Numbers[大数乘法][一般]
查看>>
三维空间中的几种坐标系
查看>>
乘法表
查看>>
4.express 框架
查看>>
Java基础算法集50题
查看>>
Android 桌面组件widget
查看>>
centos6.5 bugzilla4.4.5 汉化
查看>>
ros topic 发布一次可能会接收不到数据
查看>>
字符串的扩展
查看>>
冒泡排序_c++
查看>>