Python 101 by Michael Driscoll

By Michael Driscoll

The best way to software with Python three from starting to finish.

Show description

Read or Download Python 101 PDF

Best programming: programming languages books

Prototype and Scriptaculous: Taking the Pain out of JavaScript

This brief minimize demonstrates easy methods to use Prototype for a variety of initiatives, together with occasion dealing with, DOM processing, string and shape approach, and Ajax communications. It explores Scriptaculous' visible results library, from pulsate to squish to fold and past. want interface elements? you will discover shape autocompletion in addition to drag and drop help.

Fast Track to Sun Certified Java Program

If you want to profit the recent positive factors in Java SE five. zero and go the sunlight qualified Java Programmer improve examination (CX-310-056), then this e-book is for you. It covers all of the Java SE five. zero new positive aspects required within the examination. you do not need to examine the present beneficial properties that you simply already comprehend. 117 evaluation questions and ridicule examination questions are incorporated.

Additional resources for Python 101

Sample text

You no longer have to close the file handle explicitly as the with operator does it automatically! See if you can change some of the earlier examples from this chapter so that they use the with method too. Catching Errors Sometimes when you are working with files, bad things happen. The file is locked because some other process is using it or you have some kind of permission error. When this happens, an IOError will probably occur. In this section, we will look at how to catch errors the normal way and how to catch them using the with operator.

In Python, this operation will cause an error, as you can see in the first half of the example. To catch the error, we wrap the operation with a try/except statement. ") This is not recommended! In Python, this is known as a bare except, which means it will catch any and all exceptions. The reason this is not recommended is that you don’t know which exception you are catching. When you have something like except ZeroDivisionError, you are obviously trying to catch a division by zero error. In the code above, you cannot tell what you are trying to catch.

The second example has the backslash appropriately escaped. if __name__ == “__main__” You will see a very common conditional statement used in many Python examples. This is what it looks like: 1 2 if __name__ == "__main__": # do something! You will see this at the end of a file. This tells Python that you only want to run the following code if this program is executed as a standalone file. I use this construct a lot to test that my code works in the way I expect it to. We will be discussing this later in the book, but whenever you create a Python script, you create a Python module.

Download PDF sample

Rated 4.96 of 5 – based on 26 votes