Filtering python string through external program

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2010-04-19T20:25:31Z Indexed on 2010/04/19 20:33 UTC
Read the original article Hit count: 199

Filed under:

What's the cleanest way of filtering a Python string through an external program? In particular, how do you write the following function?

def filter_through(s, ext_cmd):
  # Filters string s through ext_cmd, and returns the result.

# Example usage:
#   filter a multiline string through tac to reverse the order.
filter_through("one\ntwo\nthree\n", "tac")
#   => returns "three\ntwo\none\n"

Note: the example is only that - I realize there are much better ways of reversing lines in python.

© Stack Overflow or respective owner

Related posts about python