文件名:dictionary.txt
从文本文件导入到一个字典
YAHOO:YHOO
GOOGLE INC:GOOG
Harley-Davidson:HOG
Yamana Gold:AUY
Sotheby’s:BID
inBev:BUD
代码:
infile = open('dictionary.txt', 'r')
content= infile.readlines()
infile.close()
counters ={}
for line in content:
counters.append(content)
print(counters)
我试图导入file.txt的内容到词典中。我已经通过堆栈溢出进行搜索,但请以简单的方式回答(而不是打开...)
与文件打交道时,你应该使用'open()的函数'这样或那样的(无论如何) – RomanPerekhrest