function .__ code__ özniteliği, sanal makine bayt kodunu kapsülleyen bir nesne döndürür.
def f(): return 3
print(dir(f.__code__))
print(f.__code__.co_code) # raw compiled bytecode
Bilgiye erişmenin başka bir yolu, bir dosyayı açıkça derlemektir. Çok okunaklı şekilde, bayt kodu erişmek için basit ve komik bir yol
>>> c = compile('test.py', 'test.py', 'exec')
>>> print(c.co_code) # here is some bytecode
çalıştırmaktır: Eğer piton istemini yazabilirsiniz, Sonra
def f(): return 3
: Burada dosya test.py
olduğunu
python -m dis test.py
verir:
0 bir terminalde (burada
dis
Çözücü olan)
1 0 LOAD_CONST 0 (<code object f at 0x7fe8a5902300, file "p.py", line 1>)
3 LOAD_CONST 1 ('f')
6 MAKE_FUNCTION 0
9 STORE_NAME 0 (f)
12 LOAD_CONST 2 (None)
15 RETURN_VALUE
Bu bayt kodu platform bağımlı değil. VM. byte nihai değişiklikler hakkında
, ben
this file almış ve iki kez sökülüp:
python3 -m dis file.py > test1
python3 -m dis file.py > test2
Sonra basit bir fark gösterir: değişikliklerin başta ithalat ilgili olan
89c89
< 26 204 LOAD_CONST 13 (<code object search_concept at 0x7f40de337300, file "powergrasp/compression.py", line 26>)
---
> 26 204 LOAD_CONST 13 (<code object search_concept at 0x7fd8de5ab300, file "powergrasp/compression.py", line 26>)
104c104
< 240 LOAD_CONST 19 (<code object compress_lp_graph at 0x7f40de340780, file "powergrasp/compression.py", line 55>)
---
> 240 LOAD_CONST 19 (<code object compress_lp_graph at 0x7fd8de5b4780, file "powergrasp/compression.py", line 55>)
Yüklenen modüllerin adresi derleme sırasında aynı değildir.
Bence tercüman versiyonu ile değişebilir. – wRAR