Give code example with list storage in txt file

Closed due to the fact that off-topic participants insolor , aleksandr barakin , rdorn , Vadim Ovchinnikov , Qwertiy Jun 14 '17 at 19:54 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The message contains only the text of the task, in which there is no description of the problem, or the question is purely formal (" how do I do this task ") . To reopen the question, add a description of the specific problem, explain what does not work, what you see the problem. " - insolor, aleksandr barakin, rdorn, Vadim Ovchinnikov, Qwertiy
If the question can be reformulated according to the rules set out in the certificate , edit it .

2 answers 2

Serialization in JSON leads to the conversion of the Python list into text, which will be stored, strictly speaking, in a text file.

import json test_l = [ 1, 2, 3, 4, 5 ] with open('test.txt', 'w') as f: json.dump(test_l, f) 
     import pickle data = [1, 2, 3] with open('data.txt', 'wb') as f: pickle.dump(data, f) with open('data.txt', 'rb') as f: data_new = pickle.load(f) 

    In this example, using the pickle module, the list was saved to a text file, and then loaded from this text file.

    The pickle module allows you to serialize to save to a file or transfer over the network not only lists, but also many other objects. Standard Python data structures are all supported, emnip.

    For more information google module pickle.

    Advice for the future: try not to formulate questions like this. A good question includes a clear description of what result you want to get in the end, and what exactly is the problem that does not allow you to get this result yourself.