How do you code in Python ???

Quinn Dunkan quinn at groat.ugcs.caltech.edu
Mon May 20 22:19:15 EDT 2002


On Fri, 17 May 2002 22:50:41 +0000 (UTC), Greg Weeks
<weeks at vitus.scs.agilent.com> wrote:
>Shagshag (shagshag13 at yahoo.fr) wrote:
>: Newbie to python, i was wondering how *skilled* guys code with it :
>
>I use an ascii editor (emacs) in text mode.  I typically write lots of code
>before executing anything.  I test the code by executing programs from the
>Unix command line.

I write modules in vi in one window.  In another window, I have a python repl
in which I try out the stuff I write.  Often, I'll write a test() function
in the module that generates a testable version of whatever object in which I
happen to be interested at the moment.

I also often do something like:

>>> x = 'reload(somemodule); c = somemodule.test(); c.changestate(blah)'

and then 'exec x' whenever I want to try a new version.  Almost as nice as
a lispish (in-package :somemodule).  Only annoying thing is that python objects
don't automatically update themselves when their classes are redefined, so all
your random scratch objects lying around in the REPL will be obsolete when you
reload.  And there's the usual reload problem if there are multiple modules
involved---you have to reload them all and in the right order.

In practice, my activities are simple enough that those things don't bother me.

Lazy languages like haskell are nice because you can write all your scratch
test object assignments in the module without having to worry about how long it
might take to compute all of them.  In python I wrap 'em in thunks (which is
really what the test() convention is).



More information about the Python-list mailing list