擅长:python、mysql、java
<p><code>write</code>接受字符串。所以你可以构造一个字符串然后一次传递它。你知道吗</p>
<pre><code>myfile = open ("bob.txt","w")
myfile.write('\n{}\n{}\n{}'.format(user1strength, user2strength, user2skill))
myfile.close()
</code></pre>
<p>另外,如果您的python支持<code>with</code>,您可以这样做:</p>
<pre><code>with open("bob.txt", "w") as myfile:
myfile.write('\n{}\n{}\n{}'.format(user1strength, user2strength, user2skill))
# code continues, file is closed properly here
</code></pre>