擅长:python、mysql、java
<p>这可以使用python中的函数<code>split()</code>来完成。使用函数将允许您重用代码。在</p>
<pre><code>def create_list(filename):
element_list = []
with open(filename) as f:
for line in f:
line_data = line.split(',')
'''you can change line_data[0] to line_data[1]
if you want to print the next half of the txt line'''
element_list.append(line_data[0])
return element_list
print(create_list('file.txt'))
</code></pre>
<p>如果需要,可以稍后将行_data[1]附加到另一个列表中。在</p>