擅长:python、mysql、java
<p>尝试一下,它将消除替换换行符的需要,而且非常简单,但很有效:</p>
<pre><code>clothes = {}
with open('clothes.txt', 'r', newline = '/r/n') as clothesfile:
for line in clothesfile:
key = line.split(',')[0]
value = line.split(',')[1:]
clothes[key] = value
</code></pre>
<p>“with”语句将确保在执行实现字典的代码后关闭文件读取器。从那里你可以尽情地使用这本词典!在</p>