== Using Python to test system behavior One of the things I like about the Python interpreter is that it is just about right for doing little system behavior tests, like how various systems handled a [[TCP port binding issue ../programming/WhyPortBindingRestriction]]. This is because Python is low level enough to be relatively close to the actual system, so you can be pretty sure that what you're seeing isn't Python-specific behavior, while at the same time being high level enough that you can do the tests in a couple of lines. Strictly speaking you don't need an interpreter for this, just a language at the right level, but having an interpreter avoids the whole drag of editing and running and re-editing and re-running and so on. (And theoretically you can write this stuff directly in C, but I'm certainly not familiar enough with things like the C socket API that I can toss off test programs for this in ten minutes or less. In Python I can bind a socket in three statements, and one of them is '_import socket_'.) So today when I wanted to see how _bind()_ behaved on Solaris 9, I fired up two interpreters in two windows, and in the first I typed: > _>>> import socket \\ > >>> s = socket.socket(); s.bind[[(('', 4000))|]]_ and in the other I typed: > _>>> import socket \\ > >>> s = socket.socket(); s.bind[[(('127.0.0.1', 4000))|]]_ And the Solaris 9 machine promptly spewed a traceback complaining about '_socket.error: (125, 'Address already in use')_', just as I expected. (Yeah, I could have done it all in one Python interpreter; I didn't feel like seeing if Solaris did something funny if the same process was doing both _bind()_s. (It turns out it doesn't.))