If you have Emacs, the Python Emacs mode (or is that the Emacs Python
mode? :-) has a few commands that make it really easy to try out
pieces of Python -- ^C-^C executes the current buffer, either in a
fresh Python interpreter or in an interactive Python interpreter in
another window/buffer that you have started before with ^C-!.
Without Emacs, e.g. on the Mac, you can often get by using reload() or
execfile(). Reload() takes a module object that has already
successfully been imported and re-parses and then re-executes the
module. I often structure my modules so that all the essential code
is in a function test(). I can then do the following:
>>> import spam
>>> spam.test() # first test
(goes blatantly wrong; edit the source in another window)
>>> reload(spam)
>>> spam.test() # second test
(etc.)
Note that if the first "import spam" statement fails, there are two
possibilities: if it's a syntax error in spam, you should fix the
error and import again; if it's a run-time error in spam, you should
fix the error, and then:
>>> import spam # doesn't re-read the file
>>> reload(spam) # re-read the file
>>> spam.test()
Hope this helps,
--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>