我要做的功能很简单,获取各个国家手机号的区号,
如我的手机号+8618957901025,能将86获取出来,
谷歌提供了一个phonenumbers库能实现,
我当然没指望它能有Delphi版的,
但是它有Python版的,
那我不就能直接用Python4Delphi控件来搞。
l先在Windows下实现
首先在pycharm中实现的简单的功能
python代码如下:

Windows下面用Python4Delphi也写好了:

运行OK:

但我的服务端是在Linux服务器上的,据说Python4Delphi也是支持Linux的,正好来试试。
那么这三个参数在Linux平台中要填什么呢?

应该是需要一个linux下的python3动态库,
问了一下群里面,没有人在linux下面玩过Python4Delphi,
看来得自己摸一下了。
先看看python3是不是已经装好了,是什么版本


系统已经帮我装好了python了,版本为3.8.6,不用自己装了,大喜!
**那么它的python.so文件在哪个目录中呢?**得先找出来!
直接问我的ChatGPT:


杯具的是系统自带的只有python2的动态库,没有python3的,
怎么办呢?
再问一下ChatGPT试试:

原来python.so在Python的开发包中才有,那得装一个,
因为我是CenterOS,那么在终端输入sudo yum install python3-devel

安装成功了,
python.so有了!路径如下:
/usr/lib64/libpython3.6m.so

人工智能果然名不虚传!
l安装三方库
接下来安装谷歌的phonenumbers库,
在终端中输入pip3 install phonenumbers

提示我权限还不够,前面得加个sudo,
sudo pip3 install phonenumbers

l好了,材料都准备好了,开始动工了:
初始PythonEngine组件:

给工程添加Linux平台:



切换到Linux平台运行:

搞定!
Python4Delphi不仅能让Python语言集成到Delphi程序中运行,
同时也能弥补Python语言在界面开发上的短板,
两者就像倚天剑与屠龙刀,双剑合壁的话,所向披靡!
还支持MacOS哦!
这当然还得感谢ChatGPT,让我告别在百度一堆广告中苦苦找寻答案的日子!
也欢迎大家来使用!