将python源代码转换为json可转储数据(dict和带有字符串、int等的列表)
ast2json的Python项目详细描述
简介:ast2json是一个小模块,它可以将任何python ast节点转换成其ast
最新版本
pip-install-git+git://github.com/psycojoker/ast2json.git
用法
==
:
:
>>;导入json
>;从ast-import导入json
>;从ast-import导入ast2json
>
>;gt;gt;gt;gt;ast=ast2json(parse(open('some'u-python-source.py'u-file.py'.py'.pyt').com/gt;
;用法
>>
read()))
>>>>打印json.dumps(ast,indent=4)
str2json(open('some_python_source_file.py').read())
示例
=
这是转换“打印“hello world!”的结果。(并在结果上应用json.dumps)。
:
{
{
“body”:[
{
“\u type”:“print”,
“nl”:true,
“col\u offset”:0,
“dest”:null,
“values”:[
{
“s”:“你好,世界!”,
“_type”:“str”,
“lineno”:1,
“col_offset”:6
}
],
“lineno”:1
}
],
“U型”:“模块”
>
>changlog
==
>0.2.1(2016-11-13)
--------
*修复@abolger安装的破损管道
>
>
>0.2.1.1(2016-11-11-13)
=>
=>
==
bsd
最新版本
pip-install-git+git://github.com/psycojoker/ast2json.git
用法
==
:
:
>>;导入json
>;从ast-import导入json
>;从ast-import导入ast2json
>
>;gt;gt;gt;gt;ast=ast2json(parse(open('some'u-python-source.py'u-file.py'.py'.pyt').com/gt;
;用法
>>
read()))
>>>>打印json.dumps(ast,indent=4)
str2json(open('some_python_source_file.py').read())
示例
=
这是转换“打印“hello world!”的结果。(并在结果上应用json.dumps)。
:
{
{
“body”:[
{
“\u type”:“print”,
“nl”:true,
“col\u offset”:0,
“dest”:null,
“values”:[
{
“s”:“你好,世界!”,
“_type”:“str”,
“lineno”:1,
“col_offset”:6
}
],
“lineno”:1
}
],
“U型”:“模块”
>
>changlog
==
>0.2.1(2016-11-13)
--------
*修复@abolger安装的破损管道
>
>
>0.2.1.1(2016-11-11-13)
=>
=>
==
bsd