Sunday, September 26, 2010

PyMOTW: socket - Network Communication

The socket module exposes the low-level C API for communicating
over a network using the BSD socket interface. It includes the
socket class, for handling the actual data channel, and
functions for network-related tasks such as converting a server’s name
to an address and formatting data to be sent across the network.

Read more...


Saturday, September 25, 2010

Oblong Spiral Puzzle

Brian Jones posted a solution to the Oblong Spiral Puzzle recently.
I don't normally mess with puzzles, but after looking at his solution
I thought I would take a stab at it and see if I could come up with a
solution in Python that was a little less complicated.

The complete definition of the puzzle is on the Code Golf site.
The challenge is to fill in an n x m array with a sequence of
numbers starting at the upper left, and working around the outside,
spiraling inwards. For example:


$ python spiral.py 3 3
1 2 3
8 9 4
7 6 5

$ python spiral.py 4 5
1 2 3 4
14 15 16 5
13 20 17 6
12 19 18 7
11 10 9 8

Spend a few minutes thinking about the problem, then see if your solution looks anything like mine.

Updated to fix link to solution.

Sunday, September 19, 2010

PyMOTW: sysconfig - Interpreter Compile-time Configuration

In Python 2.7 sysconfig has been extracted from
distutils to become a stand-alone module. It includes
functions for determining the settings used to compile and install the
current interpreter.

Read more...


Sunday, September 12, 2010

PyMOTW: pdb - Interactive Debugger

pdb implements an interactive debugging environment for Python
programs. It includes features to let you pause your program, look at
the values of variables, and watch program execution step-by-step, so
you can understand what your program actually does and find bugs in
the logic.

Read more...


Sunday, September 5, 2010

PyMOTW: re - Regular Expressions

Regular expressions are text matching patterns described with a
formal syntax. The patterns are interpreted as a set of instructions,
which are then executed with a string as input to produce a matching
subset or modified version of the original. The term “regular
expressions” is frequently shortened to as “regex” or “regexp” in
conversation. Expressions can include literal text matching,
repetition, pattern-composition, branching, and other sophisticated
rules. A large number of parsing problems are easier to solve with a
regular expression than by creating a special-purpose lexer and
parser.

Read more...