Ch 17 Python

17 Introduction

Error handling can prevent your program crashes by providing yourself the potential sources of errors. Here is an example that asks the user to enter a number, then that number is displayed. >>> nb = int ( raw_input ( “Enter a number:” ) ) Enter a number:46 >>> print nb 46 >>> The raw_input () […]

Ch 16 Python

16 Introduction

A class defines objects that are representatives (instances) of this class. Objects can have attributes (variables associated with objects) and methods (functions associated with objects). Example of the Rectangle class: class Rectangle: “This is the Rectangle class” # Initialize an object # Define attributes with default values def __init__ ( self , long = 0.0 […]

Ch 15 Python

15.2 Module pickle

The pickle module can perform serialization and deserialization of data. It is actually encoded (in a particular way) objects that can be created in Python (variables, lists, dictionaries, functions, classes, etc..) To store them in a file and then recover without having to perform a step of parsing. 15.2.1 Coding of data To encode data […]

Ch 15 Python

15.1 Urllib2 module

The urllib and urllib2 modules allow to repatriate directly with Python files from the web. We deal only with simple examples, but feel free to deepen if necessary. There are subtle differences between urllib and urllib2 that we will not discuss here but are available on the official Python documentation. In this course, we chose to present urllib2 […]