您的位置:首页 > 编程语言 > Python开发

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
>>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: