Python : trying to match and count words with regex (expected string or buffer)
<p>I am trying to read a file and match words there has over 6 characters in it. but I keep getting this error:</p>

<pre><code>Traceback (most recent call last):
  File "dummy.py", line 9, in &lt;module&gt;
    matches = re.findall("\w{6,}", f.read().split())
  File "/usr/lib/python2.7/re.py", line 181, in findall
    return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
</code></pre>

<p>And I can't figure out why I am getting this error? The code is pasted below</p>

<hr>

<pre><code>import re

with open('test.txt', 'r') as f:
    matches = re.findall("\w{6,}", f.read().split())
    nr_long_words = len(matches)
    print (matches)
</code></pre>