By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

Python equivalent of script(1)

P: n/a
Is there anything like script(1) for python interactive sessions. From
script(1) manpage:

Script makes a typescript of everything printed on your terminal.
It is useful for students who need a hardcopy record of an
interactive session as proof of an assignment, as the typescript
file can be printed out later with lpr(1).

If the argument file is given, script saves all dialogue in file.
If no file name is given, the typescript is saved in the file
typescript.

In my case I wouldn't like to use it as a proof of anything, but I want
to get a script accessing a library system in my school -- it means
many attempts to play with urllib. I would prefer to do it in an
interactive session, but then I would love to have a record of all what
I've done, so I can edit this record into final script.
Thanks for any hint,

Matej Cepl

Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
ce**@surfbest.net writes:
I would love to have a record of all what I've done, so I can edit
this record into final script.


You can save the current input history with
import readline
readline.write_history_file("python.log")


If you want to log your whole session, including output, try using the
'screen' utility.

HTH
- Thomas

--
If you want to reply by mail, substitute my first and last name for
'foo' and 'bar', respectively, and remove '.invalid'.
Jul 18 '05 #2

P: n/a
Thanks a lot.

Jul 18 '05 #3

P: n/a
On 2005-01-01, ce**@surfbest.net <ce**@surfbest.net> wrote:
Is there anything like script(1) for python interactive sessions.


$ script transcript.txt
Script started, file is transcript.txt
$ python
...

Not sure if there's a way to shut off readline...

--
Grant Edwards grante Yow! But was he mature
at enough last night at the
visi.com lesbian masquerade?
Jul 18 '05 #4

P: n/a
ce**@surfbest.net writes:
In my case I wouldn't like to use it as a proof of anything, but I want
to get a script accessing a library system in my school -- it means
many attempts to play with urllib. I would prefer to do it in an
interactive session, but then I would love to have a record of all what
I've done, so I can edit this record into final script.
Thanks for any hint,


Emacs will do that for you, either in a shell (command shell) or in a
Python shell. Edit a python file, and type C-C ! and it'll start an
interactive python in a buffer that will save all the output.

Of course, you can also run your python after running script. That
will log everything from the python session in the script file.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.