Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I tried to use dumps() and loads() to do this in quite a few ways with no luck. I then decided to try it exactly as in the python solution that I link to in the question which works fine. Before the search I open a file for binary writing

f = open("results",'wb') which is then passed to the search. When I find a solution in the backtrack search I simply call pickle.dump(new_solution,f) and then close the file when the search is complete.

To read everything back in I have

f = open("results", "rb") temp = None results = [] while(temp != EOFError): result = pickle.load(f) if temp!=EOFError: results.append(temp)

I tried to use dumps() and loads() to do this in quite a few ways with no luck. I then decided to try it exactly as in the python solution that I link to in the question which works fine. Before the search I open a file for binary writing

f = open("results",'wb')
 

which is then passed to the search. When I find a solution in the backtrack search I simply call call

pickle.dump(new_solution,f)
 

and then close the file when the search is complete.

To read everything back in I have

f = open("results", "rb")
 temp = None
 results = []
 while(temp != EOFError):
     result = pickle.load(f)
     if temp!=EOFError:
      results.append(temp)

results.append(temp)

I tried to use dumps() and loads() to do this in quite a few ways with no luck. I then decided to try it exactly as in the python solution that I link to in the question which works fine. Before the search I open a file for binary writing

f = open("results",'wb')

which is then passed to the search. When I find a solution in the backtrack search I simply call

pickle.dump(new_solution,f)

and then close the file when the search is complete.

To read everything back in I have

f = open("results", "rb")
temp = None
results = []
while(temp != EOFError):
try:
    while(True):
        result = pickle.load(f)
    if temp!=EOFError:
        results.append(temp)
except EOFError:
    print("end of file reached")