Video: Learning how exceptions work

Exceptions are Python's key method for handling errors. Whenever you see one of Python's little error messages, like you've written some script and you run it for the first time and it dumps you out with stack trace and an error message, those error messages are simply uncaught exceptions. You can catch exceptions in Python using try and except. For example, if you're opening a file and the file name is wrong or you don't have permissions to open the file or something like that, Python will raise an IO Error exception.

Due to its power, simplicity, and complete object model, Python has become the scripting language of choice for many large organizations, including Google, Yahoo, and IBM. In Python 3 Essential Training, Bill Weinman demonstrates how to use Python 3 to create well-designed scripts and maintain existing projects. This course covers the basics of the language syntax and usage, as well as advanced features such as objects, generators, and exceptions. Example projects include a normalized database interface and a complete working CRUD application. Exercise files accompany the course.

Learning how exceptions work

Exceptions are Python's key method for handling errors.Whenever you see one of Python's little error messages, like you've written somescript and you run it for the first time and it dumps you out with stack traceand an error message, those error messages are simply uncaught exceptions.You can catch exceptions in Python using try and except.For example, if you're opening a file and the file name is wrong or you don'thave permissions to open the file or something like that, Python will raisean IO Error exception.

You can catch the exception like this, using try and except.Then you can even capture Python's error message, print it, and either continuewith your execution or give a user some intelligible error message or whateverexactly it is that you want to do with the error.And then you can use else for conditions where you don't get the error at all,and it just works the way that you expect it to.Of course, you can also raise your own exceptions with the raise statement.You have access to this entire exception handling process. It's built intoPython for your own error conditions in the modules, objects, and functionsthat you write yourself.

So let's go ahead and take a look at how Python uses exceptions for its error reporting.

Q: The installation process for the PyDev Eclipse plug-in doesn’t work as described in the videos. What should I do?

A: The version of Eclipse used in the recording of Python 3 Essential Training was Eclipse 3.5.2 (Galileo SR2) and the version of PyDev was 1.5.7. Soon after recording, the Eclipse project was updated to version 3.6, called Helios. As of this writing, the current version of Eclipse is 3.6.1 (Helios SR1).
Around the same time as these updates were being released, the PyDev project was updated as well. As of this writing, the current version of PyDev is 1.6.2. If you are using these most recent versions, the procedure for installing Eclipse itself has not changed, but the process documented in the videos for installing PyDev may not work.

Q: How do you install the pydev-interpreter in Eclipse Indigo on Mac OS X Lion? It's significantly different than what's shown in the video "Installing Python 3 and Eclipse for Mac."

A: Since this course was publishing, there have been upgrades to Mac OS X and Eclipse. In this scenario, after installing Python and Eclipse and the Pydev interpreter, there is a different directory to go to when modifying the preferences. As instructed in the movie (at around 6:40) restart Eclipse and then go to Eclipse > Preferences and drill down to Pydev > Interpreter - Python in the sidebar. Click New and in the Select interpreter dialog that opens, click Browse.

The Open dialog box will open, but does not appear to display your hard drive. You must press and hold the Command+Shift+Period keys. This will display all hidden files on your system. Navigate to the new path ~/Library/Frameworks/Python.framework/versions/3.2/bin/python 3.2 and click Open.

You should be able to proceed normally from there.

Q: When I try to install PyDev, it's not showing up in the Available Software window.

A: This can happen if the pydev.org/updates site is down.

You can manually download PyDev from the pydev.org web site, or from my site here:

http://python.bw.org/

Installation is simple. I've included instructions on my web site above.

Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.

Already a member ?

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships.
Learn more

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

new course releases

newsletter

general communications

special notices

Here’s our privacy policy with more details about how we handle your information.