saving a structure of a list with the data in a text file using Python
Question: I have a list of lists of tuples which I want to save in a text file as a
string and later read it from another Python script and use ast.literal_eval
to transform it from string to list.

My question is if its possible to write in a text file not only the data in
the list but the whole structure my list of lists of tuples has.

For example to have a text file like this:

    
    
    [[(365325.342877, 4385460.998374), (365193.884409, 4385307.899807), (365433.717878, 4385148.9983749995)]]
    

Does this makes sense?


Answer: This sounds like a situation better suited to `pickle` than writing to a text
file and using `ast.literal_eval`.

    
    
    >>> import pickle
    >>> l = [(1,2),(3,4)]
    >>> with open('new_pickle.txt', 'wb') as f:
        pickle.dump(l, f)
    
    >>> ================================ RESTART ================================
    >>> import pickle
    >>> with open('new_pickle.txt' ,'rb') as f:
        l = pickle.load(f)
    
    >>> l
    [(1, 2), (3, 4)]
    >>> 
    

