我可以将python词典腌制到sqlite3文本字段中吗? [英] Can I pickle a python dictionary into a sqlite3 text field?

查看:73
本文介绍了我可以将python词典腌制到sqlite3文本字段中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该知道的任何陷阱吗?我可以将其存储在文本字段中,还是需要使用Blob? (我对pickle或sqlite不太熟悉,所以我想确保自己对一些高级设计思想的理解是正确的.)

Any gotchas I should be aware of? Can I store it in a text field, or do I need to use a blob? (I'm not overly familiar with either pickle or sqlite, so I wanted to make sure I'm barking up the right tree with some of my high-level design ideas.)

推荐答案

如果要存储腌制的对象,则需要使用blob,因为它是二进制数据.但是,您可以说base64对腌制的对象进行编码,以获得可以存储在文本字段中的字符串.

If you want to store a pickled object, you'll need to use a blob, since it is binary data. However, you can, say, base64 encode the pickled object to get a string that can be stored in a text field.

但是,通常情况下,执行此类操作表明设计不良,因为您存储的数据不透明,因此您将失去使用SQL对该数据进行任何有用操作的能力.尽管不知道您实际上在做什么,但我实在无法在道德上做出呼吁.

Generally, though, doing this sort of thing is indicative of bad design, since you're storing opaque data you lose the ability to use SQL to do any useful manipulation on that data. Although without knowing what you're actually doing, I can't really make a moral call on it.

这篇关于我可以将python词典腌制到sqlite3文本字段中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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