Day*_*Day 7 python perl serialization
我有一个遗留数据库,其中包含使用Perl中模块的nfreeze方法编写的简单数据结构(没有CODE引用感谢)Storable.
现在我需要将这些数据加载到Python应用程序中.有谁知道Storable's 的Python实现thaw?谷歌没有帮助我.
如果涉及到它,我可以从可存储源中反向设计数据格式,但如果已经完成,我宁愿避免这种乐趣.
在代码中表达:给定一个像这样的Perl程序:
#!/usr/bin/perl
use strict;
use warnings;
use MIME::Base64;
use Storable qw/nfreeze/;
my $data = {
'string' => 'something',
'arrayref' => [1, 2, 'three'],
'hashref' => {
'a' => 'b',
},
};
print encode_base64( nfreeze($data) );
Run Code Online (Sandbox Code Playgroud)
我是在magic_function这样的Python之后:
#!/usr/bin/env python
import base64
import pprint
import sys
def magic_function(frozen):
# A miracle happens
return thawed
if __name__ == '__main__':
frozen = base64.b64decode(sys.stdin.read())
data = magic_function(frozen)
pprint.pprint(data)
Run Code Online (Sandbox Code Playgroud)
打印:
{'string': 'something', 'arrayref': [1, 2, 'three'], 'hashref': {'a': 'b'}}
Run Code Online (Sandbox Code Playgroud)
当针对Perl程序的输出运行时.