[Tutor] can i run the last saved input again
Alan Gauld
alan.gauld at btinternet.com
Sat Jul 24 21:17:05 CEST 2010
"Steven D'Aprano" <steve at pearwood.info> wrote
> Actually, you can change a lot in Python, but often you shouldn't.
OK, I'll compromise and say you can change a bit.
But I define Python as the interpreter and standard library.
> Any module you import, including builtins, can be monkey-patched
> (modified on the fly), although that's rightfully considered to be
> dangerous and best avoided except under very special circumstances.
OK, But by definition you can only do that from your own code,
so I'd argue thats not Python changing. But I'd admit its a grey
area depending on how you define Python and Change...
> And of course when you start up Python, it reads a number of
> environment
> variables and config files, which give you an opportunity to have
> Python remember your input from last session.
Actually thats true enough, and I hadn't thought about that.
You can create an arbitrary startup script that could potentially
even disable stdin or redirect it to an existing file such that it
always
reads the same input. Probably a very bad idea, but you could do it...
> versions 2.6 to 2.5. Some people use it to customize things like the
> prompt in the interactive interpreter, or install a tab-completion
> module, provide history which survives shutting down the interpreter
> (like most Linux shells already do), or otherwise provide added
> functionality such as that provided by (e.g.) IPython.
Yes, and those are valid changes and the kinds of things I referred
to when I said you can''t change much. But those don't change how
Python runs a program.
My real concern was that it sounded like the OP was confused in
his mind about how much of the functionality was Python ( the
interpreter/language) and how much was his own code. Thats why
I made the distinction. It is important not to ascribe too much
"magic"
to Python.
> So there are plenty of reasons to want Python to remember your
> input,
> and plenty of ways to do so.
I had forgotten the startup options so with that in mind I'll admit
that
yes, there are. Although for the specific example the OP gave they are
all either inappropriate or bad ideas.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list