擅长:python、mysql、java
<p>将代码放入函数中:</p>
<pre><code>def openandread(filename):
# No need to close the file if you use with:
with open(filename,"r") as File:
return_this = File.read().splitlines()
return return_this
</code></pre>
<p>然后多次调用这个函数:</p>
<pre><code>Audio = openandread("Key Words\Audio.txt")
Calls = openandread("Key Words\Calls.txt")
Charging = openandread("Key Words\Charging.txt")
</code></pre>
<p>或者如果你想把它缩短一些:</p>
<pre><code>Audio, Calls, Charging = (openandread(i) for i in ["Key Words\Audio.txt", "Key Words\Calls.txt", "Key Words\Charging.txt"])
</code></pre>