Python: Create – Modify – Reuse

0
(0)

Python: Create – Modify – Reuse
 

  • Author:James O. Knowlton
  • Length: 262 pages
  • Edition: 1
  • Publisher: Wrox
  • Publication Date: 2008-07-08
  • ISBN-10: 0470259329
  • ISBN-13: 9780470259320
  • Sales Rank: #5242370 (See Top 100 Books)
  • Download:Register/Login to Download
  • Buy Print:Buy from amazon


    Book Description

    Python: Create-Modify-Reuseis designed for all levels of Python developers interested in a practical, hands-on way of learning Python development. This book is designed to show you how to use Python (in combination with the raw processing power of your computer) to accomplish real-world tasks in a more efficient way. Don’t look for an exhaustive description of the Python language––you won’t find it. The book’s main purpose is not to thoroughly cover the Python language, but rather to show how you can use Python to create robust, real-world applications.

    In this respect, the goal is similar to foreign-language books that identify themselves as “conversational,” focusing on the vocabulary and concepts that people will need the most. Likewise, I focus specifically on the Python knowledge needed to accomplish practical, specific tasks. Along the way, you will learn to create useful, efficient scripts that are easy to maintain and enhance.

    This book is for developers with some experience with Python who want to explore how to develop full-blown applications. It is also for developers with experience in other languages who want to learn Python by building robust applications. It is well-suited for developers who like to “learn by doing,” rather than exploring a language feature by feature. To get the most out of the book, you should understand basic programming principles.

    Because this book is project-based, you can approach it in numerous ways. You can, of course, read it from cover to cover. Chapters 2 through 8 each cover a different project, so the chapters are independent of each other. However, because each chapter project is covered individually, there may be some overlap of information. I also sometimes refer to explanations of particular topics covered in previous chapters. This will help to reinforce important concepts.

    The end of the book contains two appendixes. The first one is a listing of Python resources you can check out for more information. The second one will help you with installing additional components used in some of the examples.

    This book starts with a basic overview of the Python language, designed for those familiar with other languages but new to Python. It is followed by several chapters, each of which describes a complete project that can be used as-is or modified and extended to suit your particular purposes. You’ll find applications that access databases, take advantage of web technologies, and facilitate network communications, to name a few. In addition, and more important than the technologies you will be introduced to, you will learn how to use Python to solve real challenges. Following these chapters are two chapters that cover accessing operating system resources and debugging and testing, respectively.

    Each project chapter contains complete instructions describing how to install and use the application, so you can actually see the program run as you learn how to construct and use it, including how the project was designed and prototyped. This book is intended to be both a reference guide and a learning aid, teaching you how to build solutions with Python and providing reference information on a wide variety of Python programming concepts.

    It is hoped that this book will help you have fun with Python and build useful applications, and—unlike my experience with building a deck—without sore thumbs.

    This book is framed around the code itself. This is because developers are typically looking for how to do something; and, as with many activities, you learn how to do something by watching how others do and trying it yourself. If you want to know how a for loop works, you’ll find forloops in my code, but that’s not the thrust of the book. Instead, this book shows you how to do things: how to build a content management system, how to build a test management system, how to set up a system for tracking customer follow-up, and so on. Along the way, you’ll learn how to communicate with a SQL database, how to act as a web server or communicate with one, how to access operating system services, and more.

    There are three basic components to the book:

    • Chapter 1 is a brief overview of the Python language.
    • Chapters 2–8 cover seven different programming projects, which illustrate various technologies and techniques available to Python developers.
    • Chapters 9–10 cover additional, advanced topics, which will help you as you build Python projects.

    The project chapters have a consistent structure:

    • Overview: What does the application do?
    • Using the program
    • Design
    • How it all fits together
    • Modules involved
    • Code and code explanation
    • Module/class 1 explanation
    • Module/class 2 explanation
    • Minor code file explanation
    • Testing, including suggested tests
    • Modifying the project, including some suggested adaptations
    • Summary

    Each project is designed with classes that can be reused and accessed for multiple purposes. This is one of the main benefits of object-oriented programming, so designing for reusability is a main focus of the book. The book contains the following chapters:

    1. Python Basics

    This chapter is a basic primer on the Python language, and it functions as either a quick tutorial for experienced programmers new to Python or a refresher for programmers with Python experience.

    Part I: The Projects

    2. Directory/File Snapshot Program

    This project demonstrates how to interact with files, create and manipulate data structures, and provide user output. It also touches on code design issues to improve code maintainability. Often when installing or uninstalling software, or verifying changes to a file system, it can be valuable to take a “snapshot” of the files and directories, along with their size and last-modified time. The script introduced in this chapter does just that. This chapter also explores how to capture a directory listing into a Python list, and explains how to query this list for particular values.

    3. DVD Inventory System

    This project takes advantage of Python’s capability to access and manipulate data in a SQL database. The application enables multiple users to log in to a website that provides access to a DVD inventory database. Permissions are set such that some users can add, modify, or delete entries, whereas other users have read-only access to the data.

    4. Web Performance Tester

    This project shows how to communicate with a Python web server and retrieve information regarding how long it takes to receive requested items from the web server. Although writing Python programs to work on a single computer can be useful, the real power of Python can be seen when it is used to script communication between computers on a network. Most networks contain several web servers. A nice feature of Python is that it can act as a lightweight server for various Internet protocols, such as HTTP (web) and ftp. This application enables you to monitor performance of HTTP traffic on your network.

    5. Customer Follow-Up System

    This project shows how to present a web form to the user and retrieve data from it, how to automatically format and send e-mail through an SMTP server, and how to generate an HTML-formatted report. The task for the second example is to automatically generate a customer comments e-mail message based on information the customer enters in a form. It uses the mod_pythonApache module to take the information entered in the HTTP form and then utilizes a Python script on the web server to send that information to an SMTP server for mail delivery.

    6. Test Management/Reporting System

    This project makes use of the unittestmodule to run tests against an existing application, and creates a framework for reporting test results. Testing is a vital process for developing software. This application enables users to run tests for a given piece of software, to list the previous test runs by date, to show test run results for any previously run tests, and to output the results of any test run as HTML for viewing in a web browser.

    7. Version Management System

    This project connects to a list of servers via telnet, checks the application version of a pre-set application list, and displays its results both as output and to a log file. Often, a system administrator needs to patch systems or ensure that systems have the latest application versions installed. This script is an easy way to accomplish that task. It makes use of Python’s capability to emulate a telnet client and log in to remote systems and perform functions on that remote system.

    8. Content Management System

    This project explores Plone, a popular content management system based on Python and Zope (a Python-based application server). Because Python is a very mature language, numerous applications have been built on top of it. A great thing about working with Python-based applications is that you get the benefit of a full-blown application but you can still use Python to configure and customize it.

    Part II: Advanced Topics

    9. Interacting with the Operating System

    When writing scripts “in the real world,” often it is critical to be able to access services available through (and particular to) the operating system you happen to be on. For example, suppose you wanted to read or modify the Window Registry? Or you wanted to get the Linux process ID of a particular process that is running? Is such a thing even possible? Definitely—and this chapter shows you how.

    10. Debugging and Testing

    Because I am a software tester myself, testing is a subject that is certainly close to my heart. In this chapter, I discuss why testing is important, how to put the right amount of testing into your code, and how writing automated tests can help you to actually write code more quickly. You’ll look at PyUnit, the automated testing framework for Python, and learn how to use it to test the riskiest parts of a script. You’ll also explore the Python de…

    中文:

    书名:Python:创建、修改和重复使用

    Python:创建-修改-重用是为所有对学习Python开发感兴趣的实际动手方式感兴趣的Python开发人员而设计的。本书旨在向您展示如何使用Python(与计算机的原始处理能力相结合)以更高效的方式完成实际任务。不要寻找对Python语言的详尽描述–你找不到它。这本书的主要目的不是全面介绍Python语言,而是展示如何使用Python来创建健壮的、真实的应用程序。

    在这方面,这一目标类似于将自己定位为“对话式”的外语书籍,专注于人们最需要的词汇和概念。同样,我特别关注完成实际的特定任务所需的Python知识。在此过程中,您将学会创建有用、高效、易于维护和增强的脚本。

    这本书的目标读者是有一些使用Python经验的开发人员,他们想要探索如何开发成熟的应用程序。它也适用于有其他语言经验的开发人员,他们希望通过构建健壮的应用程序来学习Python。它非常适合喜欢“边做边学”的开发人员,而不是逐个功能地探索语言功能。要最大限度地利用本书,您应该了解基本的编程原则。

    因为这本书是以项目为基础的,所以你可以用多种方法来接近它。当然,你可以从头到尾阅读它。从第2章到第8章,每个章节都涵盖了一个不同的项目,因此各章彼此独立。但是,由于每个章节的项目都是单独介绍的,因此可能会有一些信息重叠。我有时还会提到对前几章中涉及的特定主题的解释。这将有助于强化重要的概念。

    这本书的结尾有两个附录。第一个是您可以查看更多信息的Python资源列表。第二个将帮助您安装一些示例中使用的其他组件。

    本书首先对Python语言进行了基本概述,专为熟悉其他语言但对Python语言不熟悉的人设计。它后面有几章,每一章都描述了一个完整的项目,可以按原样使用,也可以根据您的特定目的进行修改和扩展。您将找到访问数据库、利用Web技术和促进网络通信的应用程序,仅举几例。此外,比将介绍的技术更重要的是,您将学习如何使用Python来解决真正的挑战。在这些章节之后是两章,分别涉及访问操作系统资源和调试和测试。

    每个项目章节都包含描述如何安装和使用应用程序的完整说明,因此在学习如何构造和使用程序时,您可以实际看到程序的运行,包括项目是如何设计和制作原型的。这本书既是一本参考指南,也是一本学习辅助工具,教您如何使用Python构建解决方案,并提供有关各种Python编程概念的参考信息。

    希望这本书能帮助您享受使用Python的乐趣,并构建有用的应用程序,而且–不像我在构建一组应用程序时所经历的那样–无需大拇指酸痛。

    这本书是围绕代码本身展开的。这是因为开发人员通常在寻找如何做某事;而且,就像许多活动一样,您通过观察他人如何做并亲自尝试来学习如何做某事。如果你想知道这是怎么回事 loop works, you’ll find 在我的代码中循环,但这不是本书的主旨。相反,本书向您展示了如何操作:如何构建内容管理系统、如何构建测试管理系统、如何设置跟踪客户跟踪的系统,等等。在此过程中,您将学习如何与SQL数据库通信,如何充当Web服务器或与之通信,如何访问操作系统服务,等等。

    这本书有三个基本组成部分:

    • 第1章是对Python语言的简要概述。
    • 第2-8章涵盖了7个不同的编程项目,它们说明了可供Python开发人员使用的各种技术和技巧。
    • 第9-10章介绍了其他高级主题,这些主题将在您构建Python项目时提供帮助。

    项目章节具有一致的结构:

    • 概述:这个应用程序做些什么?
    • 使用该程序
    • Design
    • 这一切是如何结合在一起的
    • 涉及的模块
    • 代码和代码说明
    • 模块/第1类说明
    • 模块/第2类说明
    • 次要代码文件说明
    • 测试,包括建议的测试
    • 修改项目,包括一些建议的调整
    • Summary

    每个项目都设计了可重复使用和访问多种用途的类。这是面向对象编程的主要好处之一,因此设计可重用性是本书的主要关注点。这本书包括以下几章:

    1.巨蟒基础知识

    本章是关于Python语言的基本入门读物,它既可以作为经验丰富的编程人员的快速教程,也可以作为具有Python经验的程序员的复习材料。

    第一部分:项目

    2.目录/文件快照程序

    该项目演示了如何与文件交互、创建和操作数据结构以及提供用户输出。它还涉及代码设计问题,以提高代码的可维护性。通常,在安装或卸载软件或验证对文件系统的更改时,获取文件和目录及其大小和最后修改时间的“快照”是很有价值的。本章中介绍的脚本就是这样做的。本章还探讨了如何将目录列表捕获到Python列表中,并解释了如何在该列表中查询特定值。

    3.DVD盘点系统

    该项目利用了Python访问和操作SQL数据库中的数据的能力。该应用程序使多个用户能够登录到一个网站,该网站提供对DVD库存数据库的访问。权限的设置使某些用户可以添加、修改或删除条目,而其他用户对数据具有只读访问权限。

    4.Web性能测试仪

    这个项目展示了如何与一个PythonWeb服务器进行通信,并检索有关从Web服务器接收请求项所需时间的信息。尽管编写在一台计算机上工作的Python程序可能很有用,但当使用它来编写网络上计算机之间的通信脚本时,就可以看到Python的真正强大之处。大多数网络都包含多个Web服务器。Python的一个很好的特性是,它可以充当各种Internet协议(如HTTP(Web)和ftp)的轻量级服务器。此应用程序使您能够监控网络上的HTTP流量的性能。

    5.客户跟踪系统

    该项目展示了如何向用户显示Web表单并从中检索数据,如何通过SMTP服务器自动格式化和发送电子邮件,以及如何生成HTML格式的报告。第二个示例的任务是根据客户在表单中输入的信息自动生成客户评论电子邮件。它使用的是Mod_pythonApache模块获取在HTTP表单中输入的信息,然后利用Web服务器上的一个Python脚本将该信息发送到SMTP服务器以进行邮件传递。

    6.考试管理/报告系统

    这一项目充分利用了单位测试模块对现有应用程序运行测试,并创建用于报告测试结果的框架。测试是开发软件的重要过程。此应用程序使用户能够为给定的软件运行测试,按日期列出以前的测试运行,显示任何以前运行的测试的测试运行结果,并将任何测试运行的结果以HTML格式输出,以便在Web浏览器中查看。

    7.版本管理系统

    该项目通过Telnet连接到服务器列表,检查预先设置的应用程序列表的应用程序版本,并将其结果显示为输出和日志文件。通常,系统管理员需要为系统打补丁或确保系统安装了最新的应用程序版本。此脚本是完成该任务的一种简单方法。它利用了Python的功能来模拟telnet客户端,并登录到远程系统并在该远程系统上执行功能。

    8.内容管理系统

    这个项目探索了Plone,一个流行的基于Python和Zope(一个基于Python的应用服务器)的内容管理系统。因为Python是一种非常成熟的语言,所以已经在其上构建了许多应用程序。使用基于Python的应用程序的一大好处是,您可以从一个成熟的应用程序中获益,但您仍然可以使用Python来配置和定制它。

    第二部分:高级主题

    9.与操作系统交互

    在“真实世界”中编写脚本时,能够通过您碰巧使用的操作系统(尤其是操作系统)访问可用的服务通常是至关重要的。例如,假设您想要读取或修改Windows注册表?或者您想要获取正在运行的特定进程的Linux进程ID?这样的事情有可能发生吗?当然,这一章向你展示了如何做到这一点。

    10.调试和测试

    因为我自己也是一名软件测试员,所以测试是我非常关心的话题。在本章中,我将讨论为什么测试很重要,如何在代码中放入适量的测试,以及编写自动化测试如何帮助您更快地实际编写代码。您将了解PyUnit,这是一个针对Python的自动化测试框架,并学习如何使用它来测试脚本中风险最高的部分。您还将探索巨蟒。

  • 下载电子版:下载地址
  • 购买纸质版:亚马逊商城

    点击星号评分!

    平均分 0 / 5. 投票数: 0

    还没有投票!请为他投一票。

  • 推荐阅读

    评论 抢沙发

    评论前必须登录!

     

    登录

    找回密码

    注册