0

I have the following code, what will be the best way to write that list into a file and read it back in the list format as it is. Any help will be appreciated.

l=[
            "[ 'ARAJunkyard_Build_Branch' , 7 , 6 , 1 ]",
            "[ 'ARAJunkyard_Build_Head' , 10 , 10 , 0 ]",
            "[ 'ARAJunkyard_DevUnitTests_Branch' , 10 , 9 , 1 ]",
            "[ 'ARAJunkyard_DevUnitTests_HEAD' , 10 , 0 , 10 ]",
            "[ 'ARAJunkyard_Functional_Tests' , 7 , 2 , 5 ]"]

1 Answer 1

1

Simply use pickle module, you can store almost any object using pickle:

import pickle

l=[
            "[ 'ARAJunkyard_Build_Branch' , 7 , 6 , 1 ]",
            "[ 'ARAJunkyard_Build_Head' , 10 , 10 , 0 ]",
            "[ 'ARAJunkyard_DevUnitTests_Branch' , 10 , 9 , 1 ]",
            "[ 'ARAJunkyard_DevUnitTests_HEAD' , 10 , 0 , 10 ]",
            "[ 'ARAJunkyard_Functional_Tests' , 7 , 2 , 5 ]"]

with open("test.dat", "wb") as fp:
    pickle.dump(l, fp)


with open("test.dat", "rb") as fp:
    l2 = pickle.load(fp)

print l2

http://docs.python.org/2/library/pickle.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.