Dear list,
I have a long list of commands in the form of a script and would like to
obtain a log file as if I enter the commands one by one. (The output
will be used in a tutorial.) What would be the best way to do it? Copy
and paste is not acceptable since I make frequent changes tot he
Bo Peng wrote:
I have a long list of commands in the form of a script and would like to
obtain a log file as if I enter the commands one by one. (The output
will be used in a tutorial.) What would be the best way to do it? Copy
and paste is not acceptable since I make frequent changes tot he
The 'code' module contains 'Utilities needed to emulate Python's interactive
interpreter.'. By subclassing code.InteractiveConsole and replacing the
raw_input method with one which reads from a file, I think you can get what you
want.
The example below the classes uses StringIO so that it can be
Thank you for the suggestions and code!
import code
SCRIPT = [line.rstrip() for line in open(myscript.py)]
script =
prompt =
for line in SCRIPT:
print prompt, line
script = script + line + \n
co = code.compile_command(script, stdin, exec)
if co:
# got a
[EMAIL PROTECTED] wrote:
The 'code' module contains 'Utilities needed to emulate Python's interactive
interpreter.'. By subclassing code.InteractiveConsole and replacing the
raw_input method with one which reads from a file, I think you can get what
you
want.
This method works fine with
Bo Peng wrote:
import code
SCRIPT = [line.rstrip() for line in open(myscript.py)]
script =
prompt =
for line in SCRIPT:
print prompt, line
script = script + line + \n
co = code.compile_command(script, stdin, exec)
if co:
# got a complete statement. execute
Bo Peng wrote:
This method works fine with only one minor problem. It would stop
(waiting for user input) at help(str) command. I will have to find a way
to feed the program with'q' etc.
replacing sys.stdin with something that isn't a TTY will fix this.
here's one way to do it:
class
Fredrik Lundh wrote:
replacing sys.stdin with something that isn't a TTY will fix this.
This works like magic! Thank you!
Bo
--
http://mail.python.org/mailman/listinfo/python-list