擅长:python、mysql、java
<p>试试这个:</p>
<pre><code>import csv
# Create a dictionary that will contain the file data
dic = {}
# Open the file and read it
with open('data.txt', 'r') as fd:
# contain file in a list
reader = csv.reader(fd)
# Create a counter that will be the key of a line in the file
count = 1
for row in reader:
dic[count] = row[0]
count += 1
print(dic)
</code></pre>