Sitemap
Ted James

Ted James

The world is my office, and every destination is my inspiration

Using grep from python console

Apr 25, 2025

Using python how can I make this happen?

python_shell$>  print myPhone.print_call_log()  |  grep 555

The only thing close that I’ve seen is using “ipython console”, assigning output to a variable, and then using a .grep() function on that variable. This is not really what I’m after. I want pipes and grepping on anything in the output (including errors/info).

Solution

Python’s interactive REPL doesn’t have grep, nor process pipelines, since it's not a Unix shell. You need to work with Python objects.

Get Ted James’s stories in your inbox

Join Medium for free to get updates from this writer.

So, assuming the return value of myPhone.print_call_log is a sequence:

call_log_entries = myPhone.print_call_log()
entries_containing_555 = [
entry for entry in call_log_entries
if "555" in entry]

Answered By — bignose

Answer Checked By — Senaida (FixIt Volunteer)

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

creative-commons-by-21pxcreative-commons-sa-21px

--

--

Ted James
Ted James

Written by Ted James

The world is my office, and every destination is my inspiration