Introduction

AFTER A CONFERENCE ONE YEAR, an e-mail went around the PyLadies organizers mailing list asking, “Is anyone interested in writing a Python book?” I had kicked around the idea of a programming book for a while. After teaching for a couple years and mentoring at PyLadies and other coding meetups, I realized there was a need for a new, specific sort of programming book. I didn’t jump to replying to the e-mail, however. I knew that writing a book would be a big process (boy is it!) and that it would take a lot of time and effort on my part, in the way of working on the weekends and holidays (yep, check!). I also knew that I had a full-time job teaching programming, I was the lead organizer for my local PyLadies chapter in Atlanta, Georgia, and I had children that would soon start asking, “Are you writing this weekend?”

All of the above was true (a little more than I originally thought, actually), but I knew that the book was important. There were so many of my students asking me at the end of class, “Now that I know the basics of Python, what do I do?” My answer was always something along the lines of, “You can get involved in open-source projects!” or “Take the advanced Python class!” But none of those answers satisfied them or me. The answer is, “You have to really start looking for something to work on—a problem to solve, a need that must be met.” Because, the only way to really know and understand programming and a programming language is to solve problems with said language.

But then the problem of “But I don’t have a problem that really needs to be solved” cropped up. So while I could send my students off to look at open-source projects that do, in fact, need the help, if they didn’t understand the technology, they’d be lost and give up. Then the community loses yet another programmer who may have brought interesting things to the table. So, that’s when, after lots of talking to friends and family, I realized that this book needed to be written.

Why We Wrote This Book

For all those people who came up to us and asked, over the years, “What can I do now that I understand Python basics? What things can I learn? Where do I go?” That’s why we wrote this book.

The most chronic problem in programming books that we’ve experienced and that others have also felt they experienced is that it goes from “These are the basics of a language” into very deep concepts that only people who hold Computer Science (CS) degrees would understand. And that’s not cool. Programming should be open to anyone who is interested. We should all be working toward making the bar into programming a little lower. We feel that Python accomplishes this, but we need to take it a step further and begin to understand how people learn abstract ideas and concepts, to help us help them learn.

Think of programming like learning how to build a house, but only understanding that wood is needed and how the wood works to build a house. You still need to understand structural engineering, electrical, plumbing, ventilation, HVAC, etc. The same concept is true for programming. Languages just explain the wood being used in a house. There is plenty more that is happening in harmony with the wood, and we want to help you uncover those concepts.

Who This Book For

This book is not for beginners who want to learn Python. Rather, as a reader of this book, you need to already have some Python programming under your belt. That means you’ve done some tutorials. You also understand that whitespace matters in Python and that lists are denoted with hard braces ([ ] ) while dicts (dictionaries) are denoted with curly braces ( { } ). This book is for those people who are still beginners, but who have completed a tutorial or two—folks who understand the basics of Python, but are interested to learn what all they can do with Python.

“Need is the mother of invention” goes the saying, and when you’re learning to program, this is very true. If you need a piece of software that can perform a specific function or task, it’s easy to learn a language around that need. You have a need, the language will help you, you learn the language, you solve the problem, you’ve learned a thing, and you’ve put it to use immediately. This is awesome and fantastic! However, what if you think programming is interesting, but you’re missing the need? What if you don’t know what to make? That’s where this book comes in.

This book will help you to learn the parts of Python that most people don’t think to tell new programmers about. Most of the things covered in this book are tools and technologies that one may only discover when they are faced with working with them. However, for new programmers who don’t have a specific problem to solve, learning these tools can be difficult. Most of the time no one thinks to introduce these topics to programmers because they are used so regularly. We hope to take you on a journey through the power of Python and all of its splendor.

You will learn how to make a web app, how to talk to a database using Python libraries, and which system tools can help speed up your workflow, if you’re a systems administrator. We will briefly touch on topics such as security and best practices. You’ll get an overview of creating graphical user interfaces (GUIs) using Python libraries. We will cover consuming and producing application programming interfaces (APIs) and many other topics that are beneficial to Python programmers.

What You Will Learn

We hope to take you on a small tour of the basics that are available in the Python ecosystem. We’ll introduce you to many concepts that are usually discovered only while working on a problem to solve. While we can’t put everything into the context of problems that you may need to solve in the future, we hope that we can illustrate the powerful features of the Python language and the available packages and technology that are available to you, the new Python programmer.

We will start out with a brief “crash course” in Python, in case you’ve forgotten anything. We’ll go over the basics, and then you can decide if you want to read that chapter in its entirety or not. Next, we go over Python as a scripting language. You’ll get to get your hands dirty, as it were, by writing small scripts to access parts of your system, using Python. This should illustrate the very basic power you have with the language. Third, we’ll start talking about data, which is what programming is all about—manipulating data. You’ll get to dive in and work through some examples using some of the standard libraries that come out of the box with Python. We’ll even discuss databases so that you can get a quick intro into those. We want you to see and touch every part of a system that you may come in contact with.

After the first three chapters, you’ll dive into desktop applications. While these aren’t incredibly popular in Python, it is a feature of the language, and it could be useful down the line in your tenure as a Python programmer. Next, we will step out of the desktop and onto the Internet with Python as a data communicator. You’ll learn all about HTTP and the Web and how websites work under the hood. You’ll even be able to play with producing and consuming APIs. APIs confuse many new programmers; we hope to have removed much of the mystery with this chapter.

In the final chapters, we’ll show more advanced topics in Python, such as how to work with Python in bigger projects, debugging your code, creating testing-harnesses, handling errors, and even creating your own exceptions and exception handlers! Finally, there are appendices for reference while you are going through the book and after, when you’re spreading your Python wings and programming.

It is a lot of information, and it’s like a huge sandbox of tools and ideas to get you started on your journey with the language. We hope that you try things out and research more on your own time with certain concepts and ideas that interest you. We’ve included plenty of hands-on exercises to help you try out the concepts as they are presented, as well as some challenge questions in most chapters to help you exercise your newfound knowledge.

What You Need to Use This Book

In order to get the most out of this book, we recommend you have a modern computer running Python 3.3 or later, a good text editor that you are comfortable using, an Internet connection (for some parts of the book), and a healthy dose of patience and wonderment. We also recommend that you utilize Internet searching for any problems that may arise. Professional programmers don’t actually know it all; they usually only know those problems that they deal with day in and day out. A lot of the time of a professional programmer is spent researching and tracking down why a behavior is occurring. No one should ever feel bad for relying on a Google search to solve a problem. Sometimes, your Googling abilities are just as important as your programming ones.

To work through the examples and projects in this book, you will also need the source code. The source code for the samples is available for download from the Wrox website at:

www.wrox.com/go/pythonprojects

Conventions

To help you get the most from the text and keep track of what’s happening, we’ve used a number of conventions throughout the book.

How It Works

After each Try It Out, the code you’ve typed will be explained in detail.

As for styles in the text:

  • We highlight new terms and important words when we introduce them.
  • We show keyboard strokes like this: Ctrl+A.
  • We show filenames, URLs, and code within the text like so: persistence.properties.
  • We present code in two different ways:
  We use a monofont type with no highlighting for most code examples.
  We use bold to emphasize code that is particularly important in the present
  context or to show changes from a previous code snippet.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually, or to use the source code files that accompany the book. All the source code used in this book is available for download at www.wrox.com. Specifically for this book, the code download is on the Download Code tab at:

www.wrox.com/go/pythonprojects

You can also search for the book at www.wrox.com by ISBN (the ISBN for this book is 978-1-118-90866-2 to find the code. And a complete list of code downloads for all current Wrox books is available at www.wrox.com/dynamic/books/download.aspx.

Most of the code on www.wrox.com is compressed in a .ZIP, .RAR archive, or similar archive format appropriate to the platform. Once you download the code, just decompress it with an appropriate compression tool.

Errata

We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, like a spelling mistake or faulty piece of code, we would be very grateful for your feedback. By sending in errata, you may save another reader hours of frustration, and at the same time, you will be helping us provide even higher quality information.

To find the errata page for this book, go to:

www.wrox.com/go/pythonprojects

And click the Errata link. On this page you can view all errata that has been submitted for this book and posted by Wrox editors.

If you don’t spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We’ll check the information and, if appropriate, post a message to the book’s errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at http://p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com, you will find a number of different forums that will help you, not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:

  1. Go to http://p2p.wrox.com and click the Register link.
  2. Read the terms of use and click Agree.
  3. Complete the required information to join, as well as any optional information you wish to provide, and click Submit.
  4. You will receive an e-mail with information describing how to verify your account and complete the joining process.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works, as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

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

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