首页 > 编程语言 >(Python编程)"添加Python,充分混和。"

(Python编程)"添加Python,充分混和。"

时间:2023-06-27 14:32:49浏览次数:53  
标签:集成 chapter them code Python 编程 integration 添加


Programming Python, 3rd Edition 翻译
最新版本见: http://wiki.woodpecker.org.cn/moin/PP3eD

23.1. "Add Python. Mix Well. Repeat."
23.1. "添加Python,充分混和。"

In the prior chapter, we explored half of the Python/C integration picture: calling C services from Python. This mode lets programmers speed up operations by moving them to C, and to utilize external libraries by wrapping them in C extension modules and types. But the inverse can be just as useful: calling Python from C. By delegating selected components of an application to embedded Python code, we can open them up to onsite changes without having to ship a system's code.

在上一章中,我们考察了Python/C集成全景图的一半:在Python中调用C。这一模式通过将代码移植为C语言,或应用C扩展类型和模块封装的外部库,来提高程序的运行速度。但是反过来也是有用的:即在C中调用Python。如一个应用的部份组件以内嵌方式调用Python代码,我们就可以在不改变系统代码的情况下,对它们的行为作出更改。

This chapter tells this other half of the Python/C integration tale. It introduces the Python C interfaces that make it possible for programs written in C-compatible languages to run Python program code. In this mode, Python acts as an embedded control language (what some call a "macro" language). Although embedding is mostly presented in isolation here, keep in mind that Python's integration support is best viewed as a whole. A system's structure usually determines an appropriate integration approach: C extensions, embedded code calls, or both. To wrap up, this chapter concludes by discussing a handful of larger integration platforms, such as Component Object Model (COM) and Jython, which present broader component integration possibilities.
 
这一章讲述的就是Python/C集成的另一半的故事。它介绍了能让C语言的程序来运行Python代码的C接口。在这一模式下,Python是一种内嵌式的控制语言(有时也称为“宏”语言)。尽管此处是孤立地介绍内嵌Python,但是Python对集成的支持最好是作为一个整体来看待。通常是一个系统的结构决定了一个适当的集成方法:C扩展,内嵌调用,或综合应用。本章结束时将讨论一些更大型的集成平台,如组件对象模型(COM)及Jython,它们提供了更多的集成方法。
金庆的专栏


标签:集成,chapter,them,code,Python,编程,integration,添加
From: https://blog.51cto.com/u_16162321/6562863

相关文章

  • (Python编程)集成的方式
    ProgrammingPython,3rdEdition翻译最新版本见:http://wiki.woodpecker.org.cn/moin/PP3eD22.2.IntegrationModes22.2.集成的方式ThelasttwotechnicalchaptersofthisbookintroducePython'stoolsforinterfacingtotheoutsideworldanddiscussbothit......
  • Spring面向切面编程(AOP)
    在软件开发中,我们经常需要解决一些与业务逻辑无关的横切关注点(cross-cuttingconcerns),例如日志记录、性能监测、事务管理等。传统的面向对象编程方法往往将这些关注点与核心业务逻辑混杂在一起,导致代码的可维护性和可扩展性下降。为了解决这个问题,Spring框架引入了面向切面编程(AOP......
  • Python:中文域名的编码处理
    中文域名通过https://whois.aliyun.com/domain/百度.中国域名信息查询(WHOIS)结果如下DomainName:百度.中国PunyName:xn--wxtr44c.xn--fiqs8s中文域名处理print('中国'.encode('punycode'))#b'fiqs8s'print('百度.中国'.encode('punycode'))......
  • 实践讲解强化学习之梯度策略、添加基线、优势函数、动作分配合适的分数
    摘要:本文将从实践案例角度为大家解读强化学习中的梯度策略、添加基线(baseline)、优势函数、动作分配合适的分数(credit)。本文分享自华为云社区《强化学习从基础到进阶-案例与实践[5]:梯度策略、添加基线(baseline)、优势函数、动作分配合适的分数(credit)》,作者:汀丶。1策略梯度算法如图......
  • 【AGC】云数据库云侧Python SDK集成使用方法
    使用场景云数据库服务端以前支持Node.JS和Java平台的ServerSDK。现在介绍一下服务端为Python平台时的使用方法。集成准备Python环境配置1.下载Python和PyCharm并安装。2.使用安装的python本身作为解释器。3.安装AGCPythonSDK。AGC环境配置1.在AGC创建项目和应用2.开通云数据库服......
  • python-docx - 3
    1.添加图片函数:add_picture(图片文件,width=宽,height=高)如果只指定一个宽或高,则按比例缩放。1.1文档直接添加图片fromdocximportDocumentfromdocx.sharedimportCmdoc=Document()doc.add_picture("images/2.jpg",width=Cm(8))doc.save("1.docx")1.2段落......
  • python批量安装第三方库
    把需要安装的库名和版本号(版本号可写)写入txt文件: 终端输入pip安装命令,等待安装完成即可:pipinstall-rrequirements.txt-i......
  • ubuntu搭建python3.10.7(服务器第一步)
    一安装python更新Ubuntu软件源和依赖(建议操作)1-sudoaptupdate2-sudoaptinstallbuild-essentialzlib1g-devlibncurses5-devlibgdbm-devlibnss3-devlibssl-devlibreadline-devlibffi-dev3-下载安装包:wgethttps://www.python.org/ftp/python/3.10.7/Python-3.10.7......
  • python 批量删除 redis 大量数据
    #!/usr/bin/envpython#ScananddeletekeysinRedis.#Author:cdfivefromredisimportRedisimporttimedefRedisScanAndDelete(host,port,password,db,cursor,pattern,count,batch_delete_size):start_time=time.time()client=Redis(host......
  • python:一行代码读写文件
    1、读取文件lst=[line.strip()forlineinopen('data.txt')]print(lst)这里我们使用列表来处理。首先,我们打开一个文本文件,并使用for循环,逐行读取。最后,使用strip删除所有不必要的空间。通过使用列表功能,使得代码更简单,更短。list(open('data.txt'))##Usingwithwi......