Definitions in a script for the IDLE shell

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Definitions in a script for the IDLE shell

Dmitry Popov

Dear Sirs.

I have a rather simple question about IDLE operation which is quite important for me.

 

If I run a script or a module as the main script using command Run Module (or F5) it looks like all the definitions of this script (variables, functions…) are available in the interactive interpreter which is active after the main script is executed. The problem is that I could not find any documentation where this is stated directly. Does anybody know clear confirmation that this is correct?

 

In other words the question is whether IDLE command Run Module (or F5) is equivalent to start of Python from command line using the following command: python  –i  filename.py?

 

This is important for me because I’m going to use many different starting definitions to work in the IDLE interactive interpreter.

 

Regards,

Dmitry Popov

 

HPCAT, Geophysical Laboratory

Carnegie Institution of Washington

9700 South Cass Ave., Bldg. 434E

Argonne, IL 60439

 

 


_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|

Re: Definitions in a script for the IDLE shell

Terry Reedy
On 1/20/2012 3:04 PM, Dmitry Popov wrote:

> If I run a script or a module as the main script using command Run
> Module (or F5) it looks like all the definitions of this script
> (variables, functions…) are available in the interactive interpreter
> which is active after the main script is executed. The problem is that I
> could not find any documentation where this is stated directly. Does
> anybody know clear confirmation that this is correct?

Idle is a bit underdocumented.

> In other words the question is whether IDLE command Run Module (or F5)
> is equivalent to start of Python from command line using the following
> command: python –i filename.py?

Right, with the different that output from previous sessions is still
available in the window.

> This is important for me because I’m going to use many different
> starting definitions to work in the IDLE interactive interpreter.

The current behavior is not going to change. For me, this is a feature
because I can interactively print values and call functions if there is
a bug in my program. It can also be used to setup an interactive
environment, which is what you seem to want to do.

--
Terry Jan Reedy


_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev
Reply | Threaded
Open this post in threaded view
|

Re: Definitions in a script for the IDLE shell

Beni Cherniavsky-Paskin
In reply to this post by Dmitry Popov
On Fri, Jan 20, 2012 at 22:04, Dmitry Popov <[hidden email]> wrote:

In other words the question is whether IDLE command Run Module (or F5) is equivalent to start of Python from command line using the following command: python  –i  filename.py?


Yes, indeed.
You can directly inspect variables / call functions defined in the module, etc.  And if there is an exception, you can:
 >>> import pdb; pdb.pm()
to debug it "post mortem".

Note that every time you press F5, it kill the previous Python, and re-runs the file in a new python, so you'll lose all state from the previous run.
(But the history and output is retained until you exit IDLE.)

--
Beni Cherniavsky-Paskin <[hidden email]>

_______________________________________________
IDLE-dev mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/idle-dev