當前位置:成語大全網 - 新華字典 - Python裏面怎麽用字典顯示壹個txt文件裏的東西啊?

Python裏面怎麽用字典顯示壹個txt文件裏的東西啊?

def load_parts(fnname):

spec = {}

with open(fname, 'r') as fn: #此語法在python2.5或以上可以支持

for ii in fn:

i = ii.strip().split(',')

if len(i) == 3:

m = i[2].strip()

if m.isdigit():

spec[i[0].strip()] = (i[1].strip(), int(m))

return spec