Dump interpreter history?

Discussion in 'Python' started by Ken D'Ambrosio, Mar 25, 2011.

  1. Hey, all. A co-worker asked me a question, and I've got no idea how (or
    if) it can be done. Bottom line: he'd like to save off the text from an
    interpreter session, his thinking being that you've already tried to get
    what you want, and now you just need to gussy it up in an editor.

    Can this be done?

    Thanks!

    -Ken
    Ken D'Ambrosio, Mar 25, 2011
    #1
    1. Advertising

  2. Ken D'Ambrosio

    John Gordon Guest

    In <> "Ken D'Ambrosio" <> writes:

    > Hey, all. A co-worker asked me a question, and I've got no idea how (or
    > if) it can be done. Bottom line: he'd like to save off the text from an
    > interpreter session, his thinking being that you've already tried to get
    > what you want, and now you just need to gussy it up in an editor.


    If you're running on a unix system, run the "script" command before
    starting the interpreter. Then when you're finished with the interpreter,
    type "exit" to end the script session. This will create a file named
    "typescript" containing all of the input and output which occurred.

    --
    John Gordon A is for Amy, who fell down the stairs
    B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"
    John Gordon, Mar 25, 2011
    #2
    1. Advertising

  3. Ken D'Ambrosio

    Tim Chase Guest

    On 03/25/2011 04:40 PM, Daniel Mahoney wrote:
    > On Fri, 25 Mar 2011 17:03:55 -0400, Ken D'Ambrosio wrote:
    >
    >> Hey, all. A co-worker asked me a question, and I've got no idea how (or
    >> if) it can be done. Bottom line: he'd like to save off the text from an
    >> interpreter session, his thinking being that you've already tried to get
    >> what you want, and now you just need to gussy it up in an editor.

    >
    > import readline
    > readline.write_history_file([filename])


    Just to clarify (I thought Daniel's answer was so easy it must
    have misinterpreted the OP's request), that's a single string as
    a filename, not a list containing a filename. I tried

    filename = 'output.txt'
    import readline
    readline.write_history_file([filename])

    and got a traceback about the expected parameter type. For
    clarity, it should have been

    readline.write_history_file(filename)

    or

    readline.write_history_file('output.txt')

    But otherwise, Daniel's given a dead-easy solution.

    -tkc
    Tim Chase, Mar 25, 2011
    #3
  4. Ken D'Ambrosio

    Aahz Guest

    In article <>,
    Ken D'Ambrosio <> wrote:
    >
    >Hey, all. A co-worker asked me a question, and I've got no idea how (or
    >if) it can be done. Bottom line: he'd like to save off the text from an
    >interpreter session, his thinking being that you've already tried to get
    >what you want, and now you just need to gussy it up in an editor.


    I've never used it myself, but IIRC ipython does what you want very
    nicely.
    --
    Aahz () <*> http://www.pythoncraft.com/

    "At Resolver we've found it useful to short-circuit any doubt and just
    refer to comments in code as 'lies'. :)"
    --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22
    Aahz, Apr 11, 2011
    #4
  5. Ken D'Ambrosio

    rusi Guest

    script
    readline
    ipython

    all nice solutions...
    There's one more (old) one: emacs

    ie you can run python inside (under) emacs
    That way you can pun thus: your interactions with python are a session
    when you choose and a file when you choose (buffer in emacs-speak).

    [Frank admission: The emacs python modes are multiple and in a (bit of
    a) mess]
    rusi, Apr 11, 2011
    #5
  6. Ken D'Ambrosio

    Terry Reedy Guest

    On 4/11/2011 11:54 AM, Aahz wrote:
    > In article<>,
    > Ken D'Ambrosio<> wrote:
    >>
    >> Hey, all. A co-worker asked me a question, and I've got no idea how (or
    >> if) it can be done. Bottom line: he'd like to save off the text from an
    >> interpreter session, his thinking being that you've already tried to get
    >> what you want, and now you just need to gussy it up in an editor.

    >
    > I've never used it myself, but IIRC ipython does what you want very
    > nicely.


    Idle will save the contents of the shell window, including opening slash
    line and prompts.

    --
    Terry Jan Reedy
    Terry Reedy, Apr 11, 2011
    #6
  7. Ken D'Ambrosio

    John Gordon Guest

    In <> Tim Chase <> writes:

    > > import readline
    > > readline.write_history_file([filename])


    > Just to clarify (I thought Daniel's answer was so easy it must
    > have misinterpreted the OP's request), that's a single string as
    > a filename, not a list containing a filename. I tried


    In most documentation, square brackets indicate that the enclosed item is
    optional; the brackets are not meant to be used literally.

    Therefore, this text:

    readline.write_history_file([filename])

    says "You can call write_history_file() with no arguments at all, or
    with one argument which is the name of the file to be written."

    --
    John Gordon A is for Amy, who fell down the stairs
    B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"
    John Gordon, Apr 11, 2011
    #7
  8. Ken D'Ambrosio

    Aahz Guest

    In article <>,
    Terry Reedy <> wrote:
    >On 4/11/2011 11:54 AM, Aahz wrote:
    >> In article<>,
    >> Ken D'Ambrosio<> wrote:
    >>>
    >>> Hey, all. A co-worker asked me a question, and I've got no idea how (or
    >>> if) it can be done. Bottom line: he'd like to save off the text from an
    >>> interpreter session, his thinking being that you've already tried to get
    >>> what you want, and now you just need to gussy it up in an editor.

    >>
    >> I've never used it myself, but IIRC ipython does what you want very
    >> nicely.

    >
    >Idle will save the contents of the shell window, including opening slash
    >line and prompts.


    The problem is that normally you *don't* want the prompts. I believe
    IPython handles that.
    --
    Aahz () <*> http://www.pythoncraft.com/

    "At Resolver we've found it useful to short-circuit any doubt and just
    refer to comments in code as 'lies'. :)"
    --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22
    Aahz, Apr 12, 2011
    #8
  9. Ken D'Ambrosio

    Terry Reedy Guest

    On 4/12/2011 12:12 PM, Aahz wrote:
    > In article<>,
    > Terry Reedy<> wrote:


    >> Idle will save the contents of the shell window, including opening slash
    >> line and prompts.

    >
    > The problem is that normally you *don't* want the prompts. I believe
    > IPython handles that.


    I have already had in mind that IDLE should be able to deal with this issue.
    http://bugs.python.org/issue11838

    --
    Terry Jan Reedy
    Terry Reedy, Apr 12, 2011
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. halfdog
    Replies:
    12
    Views:
    12,443
  2. Sam Stephenson
    Replies:
    1
    Views:
    225
    Andrew Walrond
    Jun 18, 2005
  3. bill

    perldb history dump?

    bill, Feb 26, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    88
  4. Replies:
    2
    Views:
    293
    nutso fasst
    Oct 17, 2006
  5. Niall
    Replies:
    3
    Views:
    166
    Niall
    Dec 6, 2006
Loading...

Share This Page