How do you program in Python?

Mike Meyer mwm at mired.org
Sun Jul 3 16:39:33 EDT 2005


anthonyberet <nospam at me.invalid> writes:

> My question isn't as all-encompassing as the subject would suggest...
>
> I am almost a Python newbie, but I have discovered that I don't get
> along with IDLE, as i can't work out how to run and rerun a routine
> without undue messing about.
>
> What I would really like is something like an old-style BASIC
> interpreter, in which I could list, modify and test-run sections of
> code, to see the effects of tweaks, without having to save it each
> time, or re-typing it over and over (I haven't even worked out how to
> cut and paste effectively in the IDLE environment).
>
> I see lots of alternate IDEs etc, but which would allow me the simple
> interface that I have described? - I really don't know about IDEs in
> general, and I suspect I would be out of my depth with one of those.
>
> Thanks, and feel free to mock ;)

Try an emacs (Xemacs is my preference). That should come with a python
editing mode, which includes the ability to send code to a Python
interpreter running in interactive mode in another window. So what you
do is edit the code in a file on disk, and then ship it all to the
interpreter (with C-c C-c). You can then use the objects defined in
the file at the interperter prompt. After you identify a bug, you edit
the function/method in question, and ship the function/class to the
interpreter with M-C-x. You can then start playing with the new
version of the function/class to check it.

Note that this behavior isn't specific to Python. It's pretty standard
emacs support for all languages that have a REPL loop. The command
keys are even the same if you change languages.

Be warned - changing a class doesn't change the code of any objects
that were defined using the old class. So you get this sequence:

x = MyClass()
x.Test()               # reveal bug in MyClass
# edit MyClass.py, fix the bug, and M-C-x the class
x.Test()               # The bug is still there!
x = MyClass()
x.Test()               # Now it's gone.

         <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list