擅长:python、mysql、java
<p>文件名似乎有问题:</p>
<pre><code>out = open("man_speech.txt", "w") # Defining out instead of man_speech
out = open("other_speech.txt", "w") # Redefining out
print(man, file=man_speech) # Using undefined man_speech
print(other, file=other_speech) # Using undefined other_speech
</code></pre>
<p>您不会将<code>open</code>的结果赋给<code>man_speech</code>,而是赋给<code>out</code>。因此出现错误消息:</p>
<pre><code>NameError: name 'man_speech' is not defined
</code></pre>
<p>代码应该是</p>
<pre><code>man_speech = open("man_speech.txt", "w")
other_speech = open("other_speech.txt", "w")
print(man, file=man_speech)
print(other, file=other_speech)
</code></pre>