Callable global function

In Python 2, you could check whether an object was callable like a function with the global callable function. In Python 3, this global function has been eliminated. To check whether an object is callable, check for the existence of the_call_ special method. In Python 2, the global zip function took any number of sequences and returned a list of tuples. The first tuple contained the first item from each sequence the second tuple contained the second item from each sequence and so on. In Python...

Halt And Catch Fire

It is not enough to test that functions succeed when given good input you must also test that they fail when given bad input. And not just any sort of failure they must fail in the way you expect. gt gt gt import roman1 gt gt gt roman1.to_roman 4000 'MMMM' gt gt gt roman1.to_roman 5000 'MMMMM' gt gt gt roman1.to_roman 9000 'MMMMMMMMM' 1. That's definitely not what you wanted that's not even a valid Roman numeral In fact, each of these numbers is outside the range of acceptable input, but the...

Serializing Datatypes Unsupported by json

Even if JSON has no built-in support for bytes, that doesn't mean you can't serialize bytes objects. The json module provides extensibility hooks for encoding and decoding unknown datatypes. By unknown, I mean not defined in JSON. Obviously the json module knows about byte arrays, but it's constrained by the limitations of the JSON specification. If you want to encode bytes or other datatypes that JSON doesn't support natively, you need to provide custom encoders and decoders for those types....

Loading Data from a json File

Like the pickle module, the json module has a load function which takes a stream object, reads JSON-encoded data from it, and creates a new Python object that mirrors the JSON data structure. File lt stdin gt , line 1, in lt module gt NameError name 'entry' is not defined gt gt gt import json gt gt gt with open 'entry.json', 'r', encoding 'utf-8' as f entry json.load f 'internal_id' '_class_' 'bytes', '_value_' 222, 213, 180, 248 , 'title' 'Dive into history, 2009 edition', 'tags'...

Introducing httpl i b

Before you can use httplib2, you'll need to install it. Visit code.google.com p httplib2 and download the latest version. httplib2 is available for Python 2.x and Python 3.x make sure you get the Python 3 version, named something like httplib2-python3-0.5.0.zip. Unzip the archive, open a terminal window, and go to the newly created httplib2 directory. On Windows, open the Start menu, select Run , type cmd.exe and press ENTER. c Users pilgrim Downloads gt dir Volume in drive C has no label....