擅长:python、mysql、java
<p>问题是您试图对一个<code>file</code>对象调用<code>replace</code>方法,而这是一个<code>string</code>方法。</p>
<p>事实上:</p>
<pre><code>>>> f = open('test.txt', 'r+')
>>> type(f)
<type 'file'>
>>> f.replace('test', 'no_test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'file' object has no attribute 'replace'
>>> 'this is a test'.replace('test', 'no_test')
'this is a no_test'
</code></pre>