Re: How do you program in Python?



anthonyberet <nospam@xxxxxxxxxx> 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@xxxxxxxxx> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
.



Relevant Pages

  • Re: 2.6, 3.0, and truly independent intepreters
    ... simple have the python language and the sip/PyQt modules available to ... All we wanted to do was embed the interpreter and language core as ... unloaded many many times in a host app. ... but lack of multiple load and unload support has been another painful ...
    (comp.lang.python)
  • Re: Python vs. Lisp -- please explain
    ... forever from potential Python users. ... and any change to the interpreter is a change to the program. ... with a Lisp chip. ... to say that Python does not compile to machine code. ...
    (comp.lang.python)
  • Re: 2.6, 3.0, and truly independent intepreters
    ... given all the great things about python. ... the machine's multiple cores to the fullest, ... fresh dynamic lib for each thread-independent interpreter (you can't ... be developed, it would be very attractive for companies to support, ...
    (comp.lang.python)
  • Re: 2.6, 3.0, and truly independent intepreters
    ... resident video) from the child process back to the parent process. ... An example would be python scripts that generate video programatically ... into its interpreter. ... documented otherwise) is that the app can make as many contexts as its ...
    (comp.lang.python)
  • Re: More than you ever wanted to know about objects [was: Is everything a refrence or isnt it]
    ... >Please note that I *am* oversimplifying here, and the nitpickers will ... >that they can pick up the details as they need them, which 98% of Python ... the interpreter goes down the ... >If the interpreter keeps walking up the inheritance tree in this way ...
    (comp.lang.python)