Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been having this problem for a while.When we pickle something, the files that we will save the pickled data into, do we create those manually?

When we write a code such as the following:

Python
save_documents = open("pickled_algos/documents.pickle","wb")
pickle.dump(documents, save_documents)
save_documents.close()




Do i need to create the pickled_algos/documents.pickle file? what exactly do I need to do?

What I have tried:

I have tried creating a file in that name but got stuck
Posted
Updated 28-Jan-18 2:20am
Comments
Richard MacCutchan 28-Jan-18 8:14am    
What is the documents object that you are trying to pickle? And check that you are pointing at the correct parent directory where pickled_algos exists.
Member 13647869 28-Jan-18 8:16am    
Thank you for your feedback MacCutchan, but it turns out that i had another problem that was causing this problem!
Richard MacCutchan 28-Jan-18 8:19am    
Then please add the information to your question and mark it as solved.
Member 13647869 28-Jan-18 8:20am    
ok....
Richard MacCutchan 28-Jan-18 8:18am    
I just ran that code and it works fine.

If you are reading the documentation, you can see that there is an option for both - writing the result to a file directly or getting it back as binary string and use it any way you like...
Your code-sample do direct write of the object 'documents' to the file 'save_documents'...

11.1. pickle — Python object serialization — Python 2.7.14 documentation[^]
Python Programming Tutorials[^]
 
Share this answer
 
Comments
Member 13647869 28-Jan-18 4:13am    
so if I create the file save-documents in my documents folder, that should do it?
Kornfeld Eliyahu Peter 28-Jan-18 5:06am    
You already opened a file at "pickled_algos/documents.pickle" that 'save_documents' pointing to it...
Member 13647869 28-Jan-18 5:42am    
That's the problem, the file isn't opening
Kornfeld Eliyahu Peter 28-Jan-18 5:56am    
And what do you mean by that?
There is an error?
Member 13647869 28-Jan-18 6:05am    
Ok hold on, let me check if we are on the same page. This file, 'pickled_algos/documents.pickle', should be created by me? As in I go to my documents, create a new file, and name it save_documents? Or does the code create it? From the examples I have seen, the code creates it. Sorry for all the questions and confusion, as i said this is all very new to me
The problem was fixed when I fixed another .py file that was linked to this.

To see the solution to that file please check the following link:

How do I solve this error[^]
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 28-Jan-18 8:29am    
It is acceptable to answer you own question when you find a solution, however yours is just not an answer...
you should add more details to those come after you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900