Passing an argument to a python script and opening a file
<p>I've built a script that takes a filename as an argument and extracts all lines that match a certain pattern. Trouble is I can't open the filename - I keep getting :</p>

<pre><code>"TypeError: coercing to unicode: need string or buffer"
</code></pre>

<p>It's complaining about the line <code>info = open(name, 'r')</code>.</p>

<p>Here's the code:</p>

<pre><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)
</code></pre>

<p>And I call it with </p>

<pre><code>`extract.py trunc.log`
</code></pre>

<p>Any ideas what I'm doing wrong?</p>
