Interactive development in Python ? la Smalltalk?

B

Bienlein

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.

Then Python could become my replacemenet for my dearly missed Smalltalk, which to my great grief meanwhile really has become quite dead, I fear. In Smalltalk you can open up an inspector window (e.g. you don't have to get into debug mode), inspect objects in it and evaluate code in it, send messaages to objects. I guess this cannot be done in Python out of the box. But if changes made in the debugger became immediately effective, this would be interactive enough for my purposes.

Thanks, Bienlein
 
S

Steven D'Aprano

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
 
C

Colin J. Williams

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.

Then Python could become my replacemenet for my dearly missed Smalltalk, which to my great grief meanwhile really has become quite dead, I fear. In Smalltalk you can open up an inspector window (e.g. you don't have to get into debug mode), inspect objects in it and evaluate code in it, send messaages to objects. I guess this cannot be done in Python out of the box. But if changes made in the debugger became immediately effective, this would be interactive enough for my purposes.

Thanks, Bienlein
If you are using Windows, PyScripter is a good choice.

I understand that, with Linux, it can also be used with Wine. I haven't
tried that.

Colin W.
 
T

Terry Jan Reedy

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.

The CPython interpreter has both a 'batch' mode (run code in a file) and
an interactive mode (run code typed in response to a prompt). It also
has a '-i' option to run code in batch mode and then switch to
interactive mode so one can interrogate visible objects and call functions.

The Idle IDE has editor windows linked to an interactive shell. When you
run code in the editor window, it saves and runs it with the -i option
so you can interactive with the results in the Shell. Compiling edited
text to bytecode is typically so fast (well under a second) as to not be
an issue.
Then Python could become my replacemenet for my dearly missed
Smalltalk, which to my great grief meanwhile really has become quite
dead, I fear. In Smalltalk you can open up an inspector window (e.g.
you don't have to get into debug mode), inspect objects in it and
evaluate code in it, send messaages to objects. I guess this cannot
be done in Python out of the box. But if changes made in the debugger
became immediately effective, this would be interactive enough for my
purposes.

Idle also has a debugger window that does some of that, though it works
better on non-Windows OSes. I have never actually used it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top