Can python IDLE be used for iterative / in-memory?

I'm not sure if I phrased the topic correctly, but essentially I'm curious if someone can develop the code in IDLE Python or a similar tool and then spit out the current code in memory via some command. I believe I have done this earlier when browsing the Lisp book, and remind you that this is a very different approach than simply rerunning static files. Any suggestions on how to do this or something similar? Thanks to

UPDATE . I ended up using a combination of IDLE using execfile and reload commands and editing the code in a separate editor (eclipse / pydev). I changed my "main" file so that nothing is executed immediately when execfile is called on it. The code in the main file and imported modules is loaded onto the current area / stack as I write new code or an error occurs. I can check directly on the IDLE command line. Once I find the problem or way forward, I then update the code in the editor, run a reload (module) for the updated modules, and then execfile (path) in the main file.

+3


source to share


1 answer


The reason this makes sense with LISP is that every LISP program is just a bunch of macros and functions, and s-expressions can be formatted automatically into a nice representation.

This is not the case in Python, where you have more complex syntax (significant spaces, decorators, many control structures, different types of string literals, etc.) and more semantic elements (classes, functions, level code, ...), so this approach won't work very well. The resulting code will be very confusing, even for the smallest projects, and the resulting code will still require a lot of "post-processing", which will slow down development somewhat.

Instead, you can just write the code in a nice text editor and



  • Use the built-in functions to integrate with the REPL (EMACS and Vim have good support for this kind of stuff) or
  • load it into the REPL with execfile

    , which will give you good text editing convenience and prompt interactivity.
  • along with the program, write a suite of unit tests. This is recommended for any non-trivial software and automates the testing of your code, so you will have to spend less time in an interactive prompt checking if the function is working correctly.

You can also grab a more fully featured IDE that supports code evaluation and full blown debugging (PyDev is an example here, thanks to sr2222).

+5


source







All Articles