I built a script that takes a file name as an argument and extracts all lines matching a specific pattern. The problem is that I cannot open the file name - I keep getting:
"TypeError: coercing to unicode: need string or buffer"
He complains about the string info = open(name, 'r').
Here is the code:
import re
import sys
print sys.argv[1:]
keyword = 'queued='
pattern = re.compile(keyword)
name = sys.argv[1:]
inf = open(name, 'r')
outf = open("test.txt", 'w')
for line in inf:
if pattern.search(line):
outf.write(line)
And I call it
`extract.py trunc.log`
Any ideas what I'm doing wrong?
source
share