擅长:python、mysql、java
<p>列出需要打开的文件:</p>
<pre><code>files_to_open = [
'file_1.txt',
'file_2.txt'
]
calls_info = {}
</code></pre>
<p>迭代列表,打开并处理:</p>
<pre><code>for file_ in files_to_open:
with open(file_) as f:
calls_info[file_] = f.read().splitlines()
</code></pre>
<p>在这里,我创建了一个<code>calls_info</code>变量。这样做就是把所有的东西都存储在字典里。它们包含键和值—要访问文件的值,只需按如下方式对其进行索引:</p>
<pre><code>calls_info[file_path] # Make sure file_path is the right path you put in the list!
</code></pre>