python 编译器pyc_有没有办法知道哪个Python版本.pyc文件被编译?
生活随笔
收集整理的這篇文章主要介紹了
python 编译器pyc_有没有办法知道哪个Python版本.pyc文件被编译?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Is there any way to know by which Python version the .pyc file was compiled?
解決方案
You can get the magic number of your Python as follows:
$ python -V
Python 2.6.2
# python
>>> import imp
>>> imp.get_magic().encode('hex')
'd1f20d0a'
To get the magic number for a pyc file you can do the following:
>>> f = open('test25.pyc')
>>> magic = f.read(4)
>>> magic.encode('hex')
'b3f20d0a'
>>> f = open('test26.pyc')
>>> magic = f.read(4)
>>> magic.encode('hex')
'd1f20d0a'
By comparing the magic numbers you'll know the python version that generated the pyc file.
總結
以上是生活随笔為你收集整理的python 编译器pyc_有没有办法知道哪个Python版本.pyc文件被编译?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux命令 socket,如何从li
- 下一篇: websocket python爬虫_p