Python的编译结果-code对象与pyc文件(Python 源码剖析第七章)
2010-11-16 23:06
281 查看
code 1 >>> source = open('e:\python\p9.py').read()
2 >>> source
3 'for a in range(1, 1000):\n\tfor b in range(1, 1000):\n\t\tfor c in range(334, 999):\n\t\t\tif(a < b and b < c and (a+b+c==1000) and (a*a+b*b==c*c)):\n\t\t\t\tprint a* b * c\n'
4 >>> code = compile(source, 'p.py', 'exec')
5 >>> type(code)
6 <type 'code'>
7 >>> dir(code)
8 ['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
9 >>> print code.co_names
('range', 'a', 'b', 'c')
>>> print code.co_filename
p.py
>>>
2 >>> source
3 'for a in range(1, 1000):\n\tfor b in range(1, 1000):\n\t\tfor c in range(334, 999):\n\t\t\tif(a < b and b < c and (a+b+c==1000) and (a*a+b*b==c*c)):\n\t\t\t\tprint a* b * c\n'
4 >>> code = compile(source, 'p.py', 'exec')
5 >>> type(code)
6 <type 'code'>
7 >>> dir(code)
8 ['__class__', '__cmp__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'co_argcount', 'co_cellvars', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno', 'co_flags', 'co_freevars', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize', 'co_varnames']
9 >>> print code.co_names
('range', 'a', 'b', 'c')
>>> print code.co_filename
p.py
>>>
相关文章推荐
- Python pyc文件与code对象相关用法
- (Python学习7)Python编译结果——code对象与pyc文件
- pyc文件反编译到Python源码
- pyc文件反编译到Python源码
- Python中的字符串对象(Python 源码剖析第三章)
- Python中的List对象(Python 源码剖析第四章)
- python 把py文件编译为pyc文件 商业用途
- Python 源码剖析(一)【python对象】
- Python 源码剖析(四)【LIST对象】
- 编译pyc文件——python无法运行其它版本编译的pyc文件的情况
- python3编译成pyc文件
- Python源码剖析[13] —— 字典对象PyDictObject(2)
- Python代码加密 源码保护--pyc文件'字节码'
- Python源码剖析[12] —— 字典对象PyDictObject(1)
- 使用uncompyle2直接反编译python字节码文件pyo/pyc
- python编译运行检错神器(将.py文件编译成.pyc文件)
- 《Python 源码剖析》之对象
- 《Python 源码剖析》之对象
- 使用uncompyle2直接反编译python字节码文件pyo/pyc
- Python工程编译成跨平台可执行文件(.pyc)