Python equivalent of script(1)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cepl@surfbest.net

    #1

    Python equivalent of script(1)

    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

  • Thomas Rast

    #2
    Re: Python equivalent of script(1)

    cepl@surfbest.n et writes:
    [color=blue]
    > I would love to have a record of all what I've done, so I can edit
    > this record into final script.[/color]

    You can save the current input history with
    [color=blue][color=green][color=darkred]
    >>> import readline
    >>> readline.write_ history_file("p ython.log")[/color][/color][/color]

    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'.

    Comment

    • cepl@surfbest.net

      #3
      Re: Python equivalent of script(1)

      Thanks a lot.

      Comment

      • Grant Edwards

        #4
        Re: Python equivalent of script(1)

        On 2005-01-01, cepl@surfbest.n et <cepl@surfbest. net> wrote:
        [color=blue]
        > Is there anything like script(1) for python interactive sessions.[/color]

        $ 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?

        Comment

        • Mike Meyer

          #5
          Re: Python equivalent of script(1)

          cepl@surfbest.n et writes:
          [color=blue]
          > 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,[/color]

          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 <mwm@mired.or g> http://www.mired.org/home/mwm/
          Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

          Comment

          Working...