Interactive development in Python à la Smalltalk?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Apr 8 05:27:50 EDT 2013


On Mon, 08 Apr 2013 01:33:13 -0700, Bienlein wrote:

> Hello,
> 
> I'm absolutely new to Python, just looked at the language description
> for the first time. The first thought that came to my mind was whether
> you can program  in Python in an interactive programming style, i.e. I
> can change code in the debugger which becomes immediately effective (no
> edit-compile loop) and I can also send messages to objects visible
> inside the debugger.

Out of the box, Python comes with an extremely powerful interactive 
environment. Just launch Python from the command prompt with no 
arguments, and it will open an interactive interpreter that allows you to 
enter commands, hit enter, and have them executed.

I strongly recommend you work through at least the beginning of the 
tutorial, and get used to the interactive interpreter. Here's the one for 
Python 2:

http://docs.python.org/2/tutorial/index.html

and version 3:

http://docs.python.org/3/tutorial/index.html



If that's not enough for you, there are third-party Python interpreters 
that do much more, such as BPython, IPython and DreamPie.

http://bpython-interpreter.org/screenshots/

http://ipython.org/index.html 

http://www.dreampie.org/.

IPython will be especially familiar to those used to Mathematica.


You can't quite edit code in live objects -- code is compiled to byte-
code for a virtual machine, and you cannot edit that -- but you can 
easily redefine objects, including functions and methods, on the fly.


py> class Test(object):
...     def method(self, arg):
...             print "argument received:", arg
... 
py> 
py> t = Test()
py> t.method(23)
argument received: 23
py> 
py> def method(self, arg):
...     print "argument received:", arg+1000
... 
py> Test.method = method
py> t.method(23)
argument received: 1023



-- 
Steven



More information about the Python-list mailing list