Python - converting textfile contents into dictionary values/keys easily

前端 未结 3 584
耶瑟儿~
耶瑟儿~ 2020-12-20 17:19

Let\'s say I have a text file with the following:

line = \"this is line 1\"
line2 = \"this is the second line\"
line3 = \"here is another line\"
line4 = \"ye         


        
3条回答
  •  独厮守ぢ
    2020-12-20 18:11

    In one line:

    d = dict((line.strip().split(' = ') for line in file(filename)))
    

提交回复
热议问题