Bin Chen wrote: > I want to do following: get a user input regex, then pass this as a > parameter to grep, and then get the result from grep. > > Any code snip to implement the similar function? I am a python newbie.
import os for line in os.popen("grep pattern *.txt"): print line, also see os.system and subprocess. note that if you want to write portable code, you can implement your own "grep" using the "re" module: import re p = re.compile(pattern) for index, line in enumerate(open(filename)): if p.match(line): print index, line, </F>
-- http://mail.python.org/mailman/listinfo/python-list