Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 898031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:58:36+00:00 2026-05-15T14:58:36+00:00

ipython ‘s %his command outputs recent commands entered by the user. Is it possible

  • 0

ipython‘s %his command outputs recent commands entered by the user. Is it possible to search within these commands? Something like this:

[c for c in %history if c.startswith('plot')]

EDIT I am not looking for a way to rerun a command, but to locate it in the history list. Of course, sometimes I will want to rerun a command after locating it, either verbatim or with modifications.

EDIT searching with ctr-r and then typing plot gives the most recent command that starts with “plot”. It won’t list all the commands that start with it. Neither can you search within the middle or the end of the commands

Solution

Expanding PreludeAndFugue’s solution here what I was looking for:

[l for l in  _ih if l.startswith('plot')]

here, the if condition can be substituted by a regex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:58:37+00:00Added an answer on May 15, 2026 at 2:58 pm

    Similar to the first answer you can do the following:

    ''.join(_ih).split('\n')
    

    However, when iterating through the command history items you can do the following. Thus you can create your list comprehension from this.

    for item in _ih:
        print item
    

    This is documented in the following section of the documentation:
    http://ipython.org/ipython-doc/dev/interactive/reference.html#input-caching-system

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In ipython >=0.11, the %paste command is required to paste indented commands. However, if
When I open a python or ipython from command-line, I don't have commands history
I have a few IPython scripts which have redundant functionality. I would like to
I love iPython and am learning RoR along with some libraries like Mechanize and
Is there a keyboard command for undoing typing in iPython? Note: I am not
Using ipython 0.11 if I type a function definition, like def f(s): print s
Python has IPython .. does OCaml have anything similar? I'd very much like to
I tried echo print 'hello' | ipython Which runs the command but ipython immediately
I tried echo print 'hello' | ipython Which runs the command but ipython immediately
Is there a command in IPython to clear the screen? EDIT: As @Saher mentions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.