2021年3月24日星期三

Creating nested dictionary from text file in python3

I have a text file of thousands of blocks like this. For processing I needed to convert it into dictionary.

Text file Pattern

[conn.abc]  domain = abc.com  id = Mike  token = jkjkhjksdhfkjshdfhsd    [conn.def]  domain = efg.com  id = Tom  token = hkjhjksdhfks    [conn.ghe]  domain = ghe.com  id = Jef  token = hkjhadkjhskhfskdj7979  

Would like to convert it into following.

d1={conn.abc:{'domain':'abc.com','id': 'Mike',token:'jkjkhjksdhfkjshdfhsd'}   conn.def:{'domain':'efg.com', 'id': 'Tom',token:'hkjhjksdhfks'}   conn.ghe:{'domain':'ghe.com', 'id': 'Jef',token:'hkjhadkjhskhfskdj7979'}}  

Thanks

https://stackoverflow.com/questions/66791608/creating-nested-dictionary-from-text-file-in-python3 March 25, 2021 at 09:03AM

没有评论:

发表评论