`
universsky
  • 浏览: 92858 次
文章分类
社区版块
存档分类
最新评论

Python : 正合你的口味 [ Python: Whetting Your Appetite ]

 
阅读更多
Python: Whetting Your Appetite
If you do much work on computers, eventually you find that there’s some task you’d like to automate. For example, you may wish to perform a search-and-replace over a large number of text files, or rename and rearrange a bunch of photo files in a complicated way. Perhaps you’d like to write a small custom database, or a specialized GUI application, or a simple game.
If you’re a professional software developer, you may have to work with several C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is too slow. Perhaps you’re writing a test suite for such a library and find writing the testing code a tedious task. Or maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application.
Python is just the language for you.
You could write a Unix shell script or Windows batch files for some of these tasks, but shell scripts are best at moving around files and changing text data, not well-suited for GUI applications or games. You could write a C/C++/Java program, but it can take a lot of development time to get even a first-draft program. Python is simpler to use, available on Windows, Mac OS X, and Unix operating systems, and will help you get the job done more quickly.
Python is simple to use, but it is a real programming language, offering much more structure and support for large programs than shell scripts or batch files can offer. On the other hand, Python also offers much more error checking than C, and, being a very-high-level language, it has high-level data types built in, such as flexible arrays and dictionaries. Because of its more general data types Python is applicable to a much larger problem domain than Awk or even Perl, yet many things are at least as easy in Python as in those languages.
Python allows you to split your program into modules that can be reused in other Python programs. It comes with a large collection of standard modules that you can use as the basis of your programs — or as examples to start learning to program in Python. Some of these modules provide things like file I/O, system calls, sockets, and even interfaces to graphical user interface toolkits like Tk.
Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary. The interpreter can be used interactively, which makes it easy to experiment with features of the language, to write throw-away programs, or to test functions during bottom-up program development. It is also a handy desk calculator.
Python enables programs to be written compactly and readably. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for several reasons:
the high-level data types allow you to express complex operations in a single statement;
statement grouping is done by indentation instead of beginning and ending brackets;
no variable or argument declarations are necessary.
Python is extensible: if you know how to program in C it is easy to add a new built-in function or module to the interpreter, either to perform critical operations at maximum speed, or to link Python programs to libraries that may only be available in binary form (such as a vendor-specific graphics library). Once you are really hooked, you can link the Python interpreter into an application written in C and use it as an extension or command language for that application.
By the way, the language is named after the BBC show “Monty Python’s Flying Circus” and has nothing to do with reptiles. Making references to Monty Python skits in documentation is not only allowed, it is encouraged!
Now that you are all excited about Python, you’ll want to examine it in some more detail. Since the best way to learn a language is to use it, the tutorial invites you to play with the Python interpreter as you read.
In the next chapter, the mechanics of using the interpreter are explained. This is rather mundane information, but essential for trying out the examples shown later.
The rest of the tutorial introduces various features of the Python language and system through examples, beginning with simple expressions, statements and data types, through functions and modules, and finally touching upon advanced concepts like exceptions and user-defined classes.
Python : 正合你的口味

如果你做很多在电脑上工作,最终你发现,有一些任务,你想实现自动化。例如,您可能要执行搜索和替换过大量的文本文件,或在一个复杂的方式重新命名和重新排列了一堆照片文件。也许你想编写一个小型的自定义数据库,或者一个专门的图形用户界面应用程序,或一个简单的游戏。

如果你是一个专业的软件开发人员,你可能有几个C / C + + / Java库工作,但发现平时写/编译/测试/重编译周期太慢。也许你正在编写一个测试套件这样的库,并找到一个乏味的任务编写测试代码。或者,也许你已经写了一个程序,可以使用扩展语言,你不想为您的应用程序的设计和实施一种全新的语言。

Python是你的语言。

你可以写一个Unix shell脚本或Windows批处理文件的某些任务,但是是最好的shell脚本,在走动文件和更改文本数据,图形用户界面的应用程序或游戏并不适合。你可以写一个C / C + + / Java程序,但它可以采取了很多的开发时间甚至第一方案草案。 Python是易于使用,可在Windows,Mac OS X和Unix操作系统,将帮助你得到更快速地完成工作。

Python是使用简单,但它是一个真正的编程语言,提供更多的结构和shell脚本或批处理文件,可以提供比大型程序的支持。另一方面,Python也提供了更多的错误检查比C,是一个非常高层次的语言,它具有高层次的内置数据类型,如灵活的数组和字典。因为拥有更多的通用数据类型,Python是适用于一个更大的问题域比Awk甚至Perl,但至少很多东西都容易在Python这些语言。

Python允许你分割你的程序模块,可以重复使用在其他Python程序。它配备了一个标准的模块,你可以使用你的程序的基础 - 或作为例子开始学习Python编程的大集合。这些模块提供了一些事情,如文件I / O,系统调用,插座,甚至像Tk图形用户界面接口。

Python是一种解释语言,它可以为您节省大量的时间在程序开发过程中是必要的,因为不需要编译和链接。解释器可以交互使用,这使得它易于试验的语言特征,写扔掉的节目,在自下而上的程序开发或测试功能。这也是一个方便的桌面计算器。

的Python使编写应用程序时紧凑和可读性。 Python写的程序通常要短得多,比同样的C,C + +或Java程序,有以下几个原因:

高层次的数据类型允许你在一条语句中表达复杂的操作;
语句的组织依赖于缩进而不是开始和结束的括号;
没有变量或参数声明是必要的。
Python是可扩展的:如果你知道如何在C程序很容易添加一个新的内置功能或模块的解释,无论是执行关键操作以最大的速度,或链接Python程序库可能只提供以二进制形式(如供应商特定的图形库)。一旦你真的上钩,你可以链接到一个应用程序用C语言编写的Python解释器,并用它作为该应用程序的扩展或命令行语言。

顺便说一句,Python语言是根据英国广播公司(BBC)节目“Monty Python的飞行马戏团”而命名的,并与爬行动物(Python:巨蟒)无关。不过我们允许并鼓励你引用文档中的"巨蟒短剧"!

现在你们都兴奋有关Python,你会想要一些更详细的检查。由于学习一门语言的最好方式就是使用它,本教程邀请你一起玩的Python解释器,当你阅读。

在下一章中,介绍Python解释器的原理。这是相当普通的信息,但尝试后显示的例子至关重要。

其余的教程通过实例介绍了Python语言和系统的各种功能,开始用简单的词汇,语句和数据类型,通过功能和模块,并最终触及异常和先进的理念,如用户定义的类。

分享到:
评论

相关推荐

    Python Tutorial 新手入门教程 PDF版.rar

     Whetting Your Appetite 开胃菜  Using the Python Interpreter使用Python解释器  More Control Flow Tools 流程控制  Data Structures数据结构  Errors and Exceptions错误和异常  标准库概览…………

    Python Tutorial

    1. 开胃菜 Whetting Your Appetite 2. 使用Python解释器 Using the Python Interpreter 2.1 调用解释器 Invoking the Interpreter 2.1.1 参数传递 Argument Passing 2.1.2 交互模式 Interactive Mode 2.2 解释...

    python3.6.5参考手册 chm

    Python参考手册,官方正式版参考手册,chm版。以下摘取部分内容:Navigation index modules | next | Python » 3.6.5 Documentation » Python Documentation contents What’s New in Python What’s New In ...

    python指南_v2.6_简体中文版

    1. Whetting Your Appetite 激起你的兴趣 .................................... 2. Using the Python Interpreter 使用 Python 解释器 ................... 2.1. Invoking the Interpreter 调用解释器 ...............

    Python Tutorial 入门指南3.6英文版

    1. Whetting Your Appetite 4 2. Using the Python Interpreter 6 2.1. Invoking the Interpreter 7 2.1.1. Argument Passing 8 2.1.2. Interactive Mode 8 2.2. The Interpreter and Its Environment 9 2.2.1. ...

    Supercharged.JavaScript.Graphics(第1版)

    Having been a video game developer for many years and being used to working with ...hopefully whetting your appetite for further exploration of the subjects covered. Experiment and have fun!

Global site tag (gtag.js) - Google Analytics