任何人都可以让我知道 Python-Pickle 到底在哪里使用,并给我一个很好的例子来理解
可能的重复:
Pickle Python 序列化
嗨,我是 python 新手。请解释一下我们到底会在哪里使用pickle,并给我一个清晰的例子来理解......如果你能做到这一点那就太好了......
Possible Duplicate:
Pickle Python Serialization
Hi I am new to python. Please explain where exactly we will use pickle and give me one clear example to understand...it would be great if you could do this....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您真正想要序列化数据、存储数据并重用它时,您就会知道。
假设在一个特定的 python 脚本中,您决定创建一个图,通常该图最好存储为列表字典。现在,您可以将它们存储为某种形式的数据库或平面文件,在这种情况下,您在读回数据时必须重建数据结构。假设您认为有能力以形式存储数据结构及其内容,并获取准确的数据结构并从头开始使用它。那里有泡菜派上用场。当您想通过网络发送数据(结构)以供另一个程序使用时,这非常有用。检查这个简单的示例和一些文档。
You will come to know when you really want to serialize the data, store it and reuse it.
Suppose in a particular python script, you decide to create a graph, usually the graph can be best stored as a dictionary of lists. Now, you can store them some form of a database or a flat file, in which case you would have to reconstruct the data structure when you read it back. Suppose, you think of having an ability to store the data-stucture and its contents in form and get back the exact data-structure and use it from the point go. There you have pickle coming in handy. This is very useful when you want to send your data(-structure) over the network for another program to consume. Check this simple example here and some documentation.