-- JinQing [2006-09-19 09:19:23]

22.1. "I Am Lost at C"

22.1. “C海迷航”

So far in this book, we've been using Python as it comes out of the box. We have used interfaces to services outside Python, and we've coded extensions as Python modules. But we haven't added any external services beyond the built-in set. For many users, this makes perfect sense: such standalone programming is one of the main ways people apply Python. As we've seen, Python comes with batteries includedinterfaces to system tools, Internet protocols, GUIs, filesystems, and much more, are already available.

目前为此,我们使用Python一直是拿来就用。我们使用了Python外部服务的接口,我们以Python模块的方式编写了扩展。但我们还没有在内建功能之上添加任何外部服务。对许多用户来说,这已足够:这种单一的编程是人们应用Python的主要方式之一。正如我们所见,Python自带电池,很多接口都已经是可用的,如系统工具箱,因特网协议,GUI,文件系统等等。

But for many systems, Python's ability to integrate with C-compatible components is a crucial feature of the language. In fact, Python's role as an extension and interface language in larger systems is one of the reasons for its popularity and why it is often called a "scripting" language. Its design supports hybrid systems that mix components written in a variety of programming languages. Because different languages have different strengths, being able to pick and choose on a component-by-component basis is a powerful concept. You can add Python to the mix anywhere you need an easy-to-use and flexible language tool, without sacrificing raw speed where it matters.

但对许多系统来说,Python与C兼容部件的集成能力是一项至关重要的语言特性。实际上,Python可在大型系统中作为扩展和接口语言是其受欢迎的原因之一,也是它常被称为“脚本”语言的原因之一。它的设计支持混合系统,可融合多种编程语言编写的部件。因为不同的语言具有不同的强项,所以能够为不同部件挑选不同语言是一个强大的概念。当你需要一种好用又灵活的语言工具时,你可以加入Python,它不会牺牲速度,而速度是重要的。

For instance, compiled languages such as C and C++ are optimized for speed of execution, but are complex to programfor developers, and especially for end users. Because Python is optimized for speed of development, using Python scripts to control or customize software components written in C or C++ can yield more flexible systems and dramatically faster development modes. Moreover, systems designed to delegate customizations to Python scripts don't need to be shipped with full source code and don't require end users to learn complex or proprietary languages. Moving selected components of a pure Python program to C can also optimize program performance.

例如,编译型语言如C和C++是针对执行速度优化的,但是对开发者来说,特别是最终用户来说,编程复杂。因为Python是针对开发速度优化的,使用Python脚本来控制或定制C或C++写的软件部件,可以产生更灵活的系统,也明显是一种更快速的开发模式。而且,如果系统设计成用Python脚本处理定制内容,就不必附带全部的源代码,也不要求最终用户去学习复杂或私有的语言。有选择地将纯Python程序的部件转化为C也可以优化程序性能。