Mailing List Archive

Extreme Newbie Question
It's probably ridiculously obvious but it's my first hour working with
Python...

In interactive mode how do you save the script that you've entered line
by line to a file?

Bob Zurer
Extreme Newbie Question [ In reply to ]
Robert Zurer <bob@bluestarscrap.com> wrote:
> It's probably ridiculously obvious but it's my first hour working with
> Python...
>
> In interactive mode how do you save the script that you've entered line
> by line to a file?

well, how do you usually save batchfiles/shell scripts
you've entered line by line to a file? :-)

...

the Python FAQ basically says "Use an external editor";
see entries:

http://www.python.org/doc/FAQ.html#1.19 (unix)
http://www.python.org/doc/FAQ.html#7.10 (windows, mac)

depending on your platform.

however, it fails to mention that Python 1.5.2 comes with
the IDLE environment, which includes a python-aware editor,
a nifty interactive "shell" window, and lots of other goodies:

http://www.python.org/doc/howto/idle/

well worth trying.

...

btw, most platforms come with some kind of trivial text
editor (e.g. Notepad on Windows), and supports cut and
paste from console windows, so you can always save stuff
you've written into Python's basic command-line interface
window...

</F>
Extreme Newbie Question [ In reply to ]
Robert Zurer wrote:
>
> In interactive mode how do you save the script that you've entered line
> by line to a file?

You don't. Interactive mode isn't really designed to
be used that way -- it's more for throwaway experimentation.

If you're developing a script, it's best to enter it
into a file right from the beginning. This is very
easy if you're using IDLE. Just open up a new window,
type in some code, save, and hit F5 to run it. Check the
output, tweak, rerun, repeat as necessary.

If you're not using IDLE, you can do much the same
thing with a text editor and a shell window side by
side. Enter your code in the text editor, and use
"python myscript.py" or whatever in the shell window
to run it.

Hope that helps,
Greg