如果你真的是要一个dict对象的话,下面这段代码应该会内存占用小一些:
f = open('./test.dat','rb')
def g():
while True:
x = f.read(16)
if not x: break
a = struct.unpack('llll', x)
yield (a[0], a[1]), (a[2], a[3])
mydict = dict(g())
如果你仅仅是希望能够用类似dict的方式来访问数据的话,建议你看看shelve模块
--
Qiangning Hong
http://www.douban.com/people/hongqn/
咔咔咔,的确!这么大,真不如使用DB了,
入SQLite 就好,也是种字典哪
--
'''Time is unimportant, only life important!
过程改进乃是开始催生可促生靠谱的人的组织!
'''http://zoomquiet.org
博 @ http://blog.zoomquiet.org/pyblosxom/
维 @ http://wiki.woodpecker.org.cn/moin/ZoomQuiet
豆 @ http://www.douban.com/people/zoomq/
看 @ http://zoomq.haokanbu.com/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Pls. usage OOo to replace M$ Office. http://zh.openoffice.org
Pls. usage 7-zip to replace WinRAR/WinZip. http://7-zip.org
You can get the truely Freedom 4 software.
如果在Linux下,也建议尝试下 BDB
在 08-1-2,wanzathe<wanz...@gmail.com> 写道:
要不再试试sqlite?
--
Best Regards,
Leo Jay