guy keren wrote:

>the problem with writing things via the interactive prompt, is that they
>"go away" when you log out. you can't look at a listing of your code (or
>can you?) - you cannot re-edit a function (or can you?).
>
>  
>
To the parenthesized questions - you can, with some IDE's, but not with
text-mode ones (at least not unless you consider emacs python mode ;-) ).
However this is probably not what they ment. I'll explain the idea in
detail:

-----
 You use two open terminals - one with python interpreter, one with an
editor (I assume you have 2 anyways - the python one comes instead of
your shell one).

 You use the python shell to run functions *and experiment* (e.g.
calling dir() on returned objects, trying out various operations,
printing contents of variables, etc.). You use the editor to
"accumulate" successful code, and edit longer stuff - such as functions.
You freely cut and paste between the two.

 Occasionally you reload the contents of your file using "execfile"
(this replaces going to the shell and running the script). This has the
benefit that in case of runtime error, the interpreter catches the
exception, so you can immediately examine the contents of some
variables, and understand the problem in detail.

 Note that after the first time you did execfile, it takes ~ 2-5
keystrokes to rerun it: crtl-r,e,x,...(typing letters until you see the
right command appear), then enter. With the 'tab: complete' setup I
suggested in the wiki, even the first time takes very few keystrokes.
 (Note: I'm not saying it's less keystrokes than the shell (it's the
same as in bash - both use the readline library) - just answering ahead
before people start saying that you have to do more typing this way).
-----

 Note that this mode of operation is completely platform independent.
You don't have to chmod files, don't have to insert unix "#!" shell
selectors etc. This breaks the dependency between the general unix
command line lesson and any other one (for example - you can demonstrate
stuff even before the "basic linux" lesson at meeting #2).

>i write them in a script and run the script.  that's how i like to do
>things - much easier to edit and repeat the tests this way (and you don't
>always test things in a FIFO order).
>
>  
>
 As you can see from above, using the interpreter does not bind you to
FIFO order either
 
 With all that said, I think that writing and running scripts is still
an important skill to learn (and your course does aim to teach
*programming* - not python as a goal).
  You could first demonstrate writing and running a small thingy with
execfile, then you say you want other people to be able to use it - even
people that don't know python and don't care which language it's written
it. So, you add the #! selector at the beginning, chmod the file, and
execute it from the shell.

לענות