Filtering python string through external program
- by Peter
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.