|
发表于 2022-11-8 13:08:04
|
显示全部楼层
- >>> def fa():
- ... x = 520
- ... def fb():
- ... x = 880
- ... print('SSSS',x)
- ... print('aaaa',x)
- ...
- >>> fa.__code__.co_consts
- (None, 520, <code object fb at 0x7f31f682cb30, file "<stdin>", line 3>, 'fa.<locals>.fb', 'aaaa')
- >>> fa.__code__.co_consts[2]
- <code object fb at 0x7f31f682cb30, file "<stdin>", line 3>
- >>> fa.__code__.co_consts[2]()
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: 'code' object is not callable
- >>> import code
- >>> code.InteractiveInterpreter().runcode(fa.__code__.co_consts[2])
- SSSS 880
- >>>
复制代码 |
评分
-
查看全部评分
|