为什么我在这个Python代码中出现此错误?

0 python

我试图通过Python提取文件中的第一个单词.

我的代码

import re

con1 = pg.DB('tk', 'localhost', 5432, None, None, 'masi', '123')                
f1="/home/masi/fy.txt"

print re.findall(r"\w+", f1.read())
Run Code Online (Sandbox Code Playgroud)

我收到了错误

Traceback (most recent call last):                                              
  File "<stdin>", line 7, in <module>
AttributeError: 'str' object has no attribute 'read'
Run Code Online (Sandbox Code Playgroud)

Mar*_*ers 5

f1.read() 应该 open(f1).read()