About this book

Hello! Python is written for people who’d like to learn more about Python and how to program. You might be completely new to programming, or you might have some prior experience; either way, Hello! Python will take you from your first steps through writing networked games and web applications.

The style of this book is different from most programming books. Rather than present a laundry list of every possible feature, I’ve chosen to show you a more real-world picture. Starting with chapter 2, you’ll be following along as we write real, useful programs—warts and all. All programming language features have a purpose, and it’s hard to recognize that purpose if you don’t see all the bugs, broken code, and badly written programs that the feature is supposed to help with.

Some of the programs in Hello! Python are improved and expanded as the book progresses, so you’ll see how Python features such as functions, classes, and modules can help keep your code under control as it expands. They will also reduce the amount of work you have to do when you need to add new parts.

I think of Hello! Python as being split into three rough sections, although that’s not explicitly mentioned in the book. The first chapters cover the basic syntax of Python, how to use libraries, some common concepts, and all the other pieces you’ll need to know to understand how things work. The middle section covers more advanced features and introduces libraries that will help you get more done without having to reinvent the wheel. In the final section, we write complete programs using frameworks, which will help you even more.

The fun doesn’t stop when you’ve finished the book. All the programs in Hello! Python are intended to be extended and reused when you write your own programs. Most experienced programmers have a library of code that they’ve previously written, and the code in this book will give you a head start on your own projects.

Roadmap

Chapter 1 gives you an introduction to Python and programming, as well as an idea of what it’s all about—why we program, and what you can do with your programs. I also step through how to install Python on Windows, Mac, or Linux, and some common issues you might run into when doing so.

Chapter 2 jumps straight into the basic building blocks of programs, and you write your first program based on Hunt the Wumpus. Over the course of the chapter, you see firsthand some of the issues that programmers face, such as how to manage complex programs and make them clear and easy to understand.

Chapter 3 teaches you about Python’s famed standard library, as well as how to import its code along with code that other programmers have written to perform common tasks. You learn how to use this code in your own programs, saving you tons of time and making your programs easier to read.

Chapter 4 shows you how to test your programs, and covers both unit testing and system testing as well as some common testing issues and solutions. As you follow along, you’ll write a simple and easily extendable to-do-list application.

Chapter 5 covers how you might use Python for business-style programming by downloading web pages, parsing the information inside them, and using that to generate emails and CSV files. It also looks at how to make your programs more robust and harder to break in the face of bad information and other errors.

In chapter 6, we write an adventure game, complete with locations, monsters, and treasure. In the process, you learn how classes work and how to design object-oriented programs.

Chapter 7 extends what you’ve learned about classes with some more advanced features, like mixins, __getattribute__, and properties. We also look briefly at some of Python’s other advanced features, such as iterators and generators, as well as regular expressions and functional programming.

Chapter 8 introduces Django and helps you get a personal todo list site up and running. You learn about Django’s templates, database handling, forms, and admin functions. The chapter also covers some common web development patterns, including RESTful design and using the right HTTP methods.

Chapter 9 teaches you how to write an arcade game, loosely based on Asteroids and Lunar Lander, using a library called Pyglet. You’ll learn about geometry, event-based programming, and timers.

Chapter 10 extends the adventure program you wrote in chapter 6 so that you and your friends can play it over a network using Telnet. You use a Python networking library called Twisted to handle all the connection handling, protocol definition, and logging needed to make the game work.

Chapter 11 takes the todo list application that we wrote in chapter 8 and updates it so that everyone can have their own todo list. You’ll learn how to handle logins, create users in Django, use Django’s generic views, secure your web applications, and deploy behind a server such as Apache or Nginx.

Finally, chapter 12 gives you some extra resources you can use as you continue learning about Python—mailing lists and user groups, as well as programs to read and explore, and other libraries you might want to investigate.

Code downloads and conventions

The source code for this book is released under the 3-clause BSD license. More information about the license is available within the source code, available from manning.com/HelloPython/.

Throughout the book, I’ve used the convention of formatting code in a monospaced font, as well as variable, class, and method names. Because this book is primarily about reading and writing code, there’s a fair bit of it—Manning uses a numbering scheme with code annotations to more thoroughly explain what particular pieces of code do.

Author Online

Purchase of Hello! Python includes free access to a private web forum run by Manning Publications where you can make comments about the book, ask technical questions, and receive help from the author and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/HelloPython. This page provides information on how to get on the forum once you’re registered, what kind of help is available, and the rules of conduct on the forum.

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It’s not a commitment to any specific amount of participation on the part of the author, whose contribution to the book’s forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions, lest his interest stray!

The Author Online forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

About the author

Anthony Briggs has been a Python programmer since early 2000. He’s currently writing a web publishing system for Ramble Communications in Melbourne. Previously he worked on a core booking system for a travel firm in Australia and Canada, eventually becoming lead developer overseeing the entire project.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.129.19