how do "real" python programmers work?

Tom Anderson twic at urchin.earth.li
Thu Jan 12 18:10:24 EST 2006


On Thu, 12 Jan 2006, bblais wrote:

> In Matlab, I do much the same thing, except there is no compile phase. I 
> have the editor on one window, the Matlab interactive shell in the 
> other.  I often make a bunch of small scripts for exploration of a 
> problem, before writing any larger apps.  I go back and forth editing 
> the current file, and then running it directly (Matlab looks at the time 
> stamp, and automagically reloads the script when I modify it).

I wouldn't describe myself as an experienced programmer, but this is 
definitely how i work - editor plus interactive interpreter, using 
import/reload to bring in and play with bits of of code.

Towards the end of coding a program, when i'm done with the inner 
functions and am working on the main function, which does stuff like 
command line parsing, setting up input and output, etc, i'll often leave 
the interpreter and work from the OS shell, since that's the proper 
environment for a whole program.

Often, i'll actually have more than one shell open - generally three: one 
with an interpreter without my code loaded, for doing general exploratory 
programming, testing code fragments, doing sums, etc; one with an 
interpreter with my code loaded, for testing individual components of the 
code, and one at the OS shell, for doing whole-program tests, firing up 
editors, general shell work, etc.

Another trick is to write lightweight tests as functions in the 
interpreter-with-code-loaded that reload my module and then do something 
with it. For example, for testing my (entirely fictional) video 
compressor, i might write:

def testcompressor():
 	reload(vidzip)
 	seq = vidzip.ImageSequence((640, 480))
 	for i in xrange(200):
 		frameName = "testmovie.%02i.png" % i
 		frame = Image.open(frameName)
 		seq.append(frame)
 	codec = vidzip.Compressor(vidzip.DIRAC, 9)
 	codec.compress(seq, file("testmovie.bbc", "w"))

Then, after editing and saving my code, i can just enter 
"testcompressor()" (or, in most cases, hit up-arrow and return) to reload 
and test. You can obviously extend this a bit to make the test routine 
take parameters which control the nature of the test, so you can easily 
test a range of things, and you can have multiple different test on the go 
at once.

tom

-- 
Only men's minds could have mapped into abstraction such a territory



More information about the Python-list mailing list