我挑食时是否需要创建文件? [英] Do I need to create files when I pickle?

查看:74
本文介绍了我挑食时是否需要创建文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直有这个问题。当我们腌制某些东西时,我们会将腌制数据存入的文件,我们是否手动创建这些文件?



当我们编写如下代码时:



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:

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









我是否需要创建pickled_algos / documents.pickle文件?我究竟需要做什么?



我的尝试:



我试过用这个名字创建一个文件但是卡住了





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

推荐答案

如果你正在阅读文档,你可以看到两者都有一个选项 - 写作将结果直接或以二进制字符串形式返回并以任何方式使用它...

您的代码示例直接将对象'documents'写入文件'save_documents' ...



11.1。 pickle - Python对象序列化 - Python 2.7.14文档 [ ^ ]

Python编程教程 [ ^ ]
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[^]


当我修复另一个链接到此文件的.py文件时问题得到解决。



要查看该文件的解决方案,请检查以下链接:



如何解决此错误 [ ^ ]
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[^]


这篇关于我挑食时是否需要创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆