Reading a list of lists from a file as list of lists in python

后端 未结 4 484
无人及你
无人及你 2020-12-19 06:49

I collected data in the form of list of lists and wrote the data into a text file. The data in the text file looks like

[[123231,2345,888754],[223467,85645]         


        
4条回答
  •  眼角桃花
    2020-12-19 07:29

    This looks like valid JSON.

    So you can simply do:

    import json
    with open(myfilename) as f:
        lst = json.load(f)
    

    To store your "list of lists" in a file, do

    with open(myfilename, "w") as f:
        json.dump(lst, f)
    

提交回复
热议问题