June 2017
Beginner
352 pages
8h 39m
English
Since exceptions are a means of control flow, they can be clumsy to demonstrate at the REPL, so in this chapter we'll be using a Python module to contain our code. Let's start with a very simple module we can use for exploring these important concepts and behaviors. Place the this code in a module called exceptional.py:
"""A module for demonstrating exceptions."""def convert(s): """Convert to an integer.""" x = int(s) return x
Import the convert() function from this module into the Python REPL:
$ python3Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> from exceptional import convert ...
Read now
Unlock full access